3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Identifiers
;
7 use Webmozart\Assert\Assert
;
8 use Webmozart\Assert\InvalidArgumentException
;
10 /** @psalm-immutable */
11 final class TriggerName
implements Identifier
14 * @see https://dev.mysql.com/doc/refman/en/identifier-length.html
15 * @see https://mariadb.com/kb/en/identifier-names/#maximum-length
17 private const MAX_LENGTH
= 64;
19 /** @psalm-var non-empty-string */
22 /** @throws InvalidTriggerName */
23 private function __construct(mixed $name)
26 Assert
::stringNotEmpty($name);
27 } catch (InvalidArgumentException
) {
28 throw InvalidTriggerName
::fromEmptyName();
32 Assert
::maxLength($name, self
::MAX_LENGTH
);
33 } catch (InvalidArgumentException
) {
34 throw InvalidTriggerName
::fromLongName(self
::MAX_LENGTH
);
38 Assert
::notEndsWith($name, ' ');
39 } catch (InvalidArgumentException
) {
40 throw InvalidTriggerName
::fromNameWithTrailingSpace();
47 * @throws InvalidTriggerName
49 * @psalm-assert non-empty-string $name
51 public static function from(mixed $name): static
53 return new self($name);
56 public static function tryFrom(mixed $name): static|
null
59 return new self($name);
60 } catch (InvalidTriggerName
) {
65 /** @psalm-return non-empty-string */
66 public function getName(): string
71 /** @psalm-return non-empty-string */
72 public function __toString(): string