phpmyadmin/libraries/classes/Dbal/DatabaseName.php
Maurício Meneghini Fauth 5faf95016f
Use DatabaseName VO for db names in Table\Partition
- Adds DatabaseName support for DatabaseInterface::selectDb method

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2021-05-21 21:30:37 -03:00

44 lines
882 B
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Dbal;
use InvalidArgumentException;
use Webmozart\Assert\Assert;
/** @psalm-immutable */
final class DatabaseName
{
/**
* @see https://dev.mysql.com/doc/refman/en/identifier-length.html
* @see https://mariadb.com/kb/en/identifier-names/#maximum-length
*/
private const MAX_LENGTH = 64;
/**
* @var string
* @psalm-var non-empty-string
*/
private $name;
/** @throws InvalidArgumentException */
public function __construct(string $name)
{
Assert::stringNotEmpty($name);
Assert::maxLength($name, self::MAX_LENGTH);
Assert::notEndsWith($name, ' ');
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
public function __toString(): string
{
return $this->name;
}
}