1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 20:34:04 +00:00

Validate in-memory db names, move SQLite-specific methods to the SQLiteManager

This commit is contained in:
lukinovec 2026-05-01 14:09:56 +02:00
parent 7363318f6e
commit 48b4837905
2 changed files with 49 additions and 35 deletions

View file

@ -28,16 +28,6 @@ trait ValidatesDatabaseParameters
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
}
/**
* Characters allowed in filenames (SQLite databases).
*
* Includes dots to support file extensions (e.g. '.sqlite').
*/
protected static function allowedFilenameCharacters(): string
{
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.';
}
/**
* Characters allowed in database user passwords.
*
@ -62,7 +52,7 @@ trait ValidatesDatabaseParameters
*
* @throws InvalidArgumentException
*/
protected function validateParameter(string|array|null $parameters, string|null $allowedCharacters = null): void
protected static function validateParameter(string|array|null $parameters, string|null $allowedCharacters = null): void
{
$allowedCharacters ??= static::allowedParameterCharacters();
@ -95,28 +85,8 @@ trait ValidatesDatabaseParameters
*
* @throws InvalidArgumentException
*/
protected function validatePassword(string|null $password): void
protected static function validatePassword(string|null $password): void
{
$this->validateParameter($password, static::allowedPasswordCharacters());
}
/**
* Ensure filename only contains allowed characters (static::allowedFilenameCharacters())
* and is not a directory name before used in file paths (e.g. SQLite database names).
*
* @throws InvalidArgumentException
* @see Stancl\Tenancy\Database\TenantDatabaseManagers\SQLiteDatabaseManager
*/
protected function validateFilename(string $filename): void
{
$this->validateParameter($filename, static::allowedFilenameCharacters());
if ($filename === '') {
throw new InvalidArgumentException('Filename cannot be empty.');
}
if (is_dir($filename)) {
throw new InvalidArgumentException("Filename ('{$filename}') cannot be a directory.");
}
static::validateParameter($password, allowedCharacters: static::allowedPasswordCharacters());
}
}