mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 11:54:04 +00:00
Convert allowlist methods into static properties
This commit is contained in:
parent
93f77a5881
commit
1ae7d58fab
2 changed files with 6 additions and 15 deletions
|
|
@ -27,10 +27,7 @@ trait ValidatesDatabaseParameters
|
|||
* Since non-password parameters don't need to use as many special characters, we use
|
||||
* a stricter allowlist here.
|
||||
*/
|
||||
protected function allowedParameterCharacters(): string
|
||||
{
|
||||
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
|
||||
}
|
||||
public static string $allowedParameterCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
|
||||
|
||||
/**
|
||||
* Characters allowed in database user passwords.
|
||||
|
|
@ -38,10 +35,7 @@ trait ValidatesDatabaseParameters
|
|||
* The allowlist for passwords is less strict than for other parameters
|
||||
* because it's more common to use more special characters in passwords.
|
||||
*/
|
||||
protected function allowedPasswordCharacters(): string
|
||||
{
|
||||
return ' !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~';
|
||||
}
|
||||
public static string $allowedPasswordCharacters = ' !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~';
|
||||
|
||||
/**
|
||||
* Ensure that parameters (database names, usernames, etc.)
|
||||
|
|
@ -58,7 +52,7 @@ trait ValidatesDatabaseParameters
|
|||
throw new InvalidArgumentException('Parameter cannot be null.');
|
||||
}
|
||||
|
||||
$allowedCharacters ??= $this->allowedParameterCharacters();
|
||||
$allowedCharacters ??= static::$allowedParameterCharacters;
|
||||
|
||||
foreach (Arr::wrap($parameters) as $parameter) {
|
||||
if (is_null($parameter)) {
|
||||
|
|
@ -93,6 +87,6 @@ trait ValidatesDatabaseParameters
|
|||
*/
|
||||
protected function validatePassword(string|null $password): void
|
||||
{
|
||||
$this->validateParameter($password, allowedCharacters: $this->allowedPasswordCharacters());
|
||||
$this->validateParameter($password, allowedCharacters: static::$allowedPasswordCharacters);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,10 +66,7 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
|
|||
*
|
||||
* Includes dots to support file extensions (e.g. '.sqlite').
|
||||
*/
|
||||
protected static function allowedDatabaseNameCharacters(): string
|
||||
{
|
||||
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.';
|
||||
}
|
||||
public static string $allowedDatabaseNameCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-.';
|
||||
|
||||
public function createDatabase(TenantWithDatabase $tenant): bool
|
||||
{
|
||||
|
|
@ -179,7 +176,7 @@ class SQLiteDatabaseManager implements TenantDatabaseManager
|
|||
*/
|
||||
protected function validateDatabaseName(string $name, string $extraAllowedCharacters = ''): void
|
||||
{
|
||||
$this->validateParameter($name, $this->allowedDatabaseNameCharacters() . $extraAllowedCharacters);
|
||||
$this->validateParameter($name, static::$allowedDatabaseNameCharacters . $extraAllowedCharacters);
|
||||
|
||||
if ($name === '') {
|
||||
throw new InvalidArgumentException('Database name cannot be empty.');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue