23 use InvalidArgumentException;
46 throw new InvalidArgumentException(
'Database must be null or a non-empty string.' );
50 throw new InvalidArgumentException(
'Schema must be null or a non-empty string.' );
52 throw new InvalidArgumentException(
'Schema must be null if database is null.' );
56 throw new InvalidArgumentException(
'Prefix must be a string.' );
58 throw new InvalidArgumentException(
'A non-empty prefix must end with "_".' );
68 if ( $domain instanceof
self ) {
72 $parts = array_map( [ __CLASS__,
'decode' ], explode(
'-', $domain ) );
77 if (
count( $parts ) == 1 ) {
79 } elseif (
count( $parts ) == 2 ) {
81 } elseif (
count( $parts ) == 3 ) {
84 throw new InvalidArgumentException(
"Domain '$domain' has too few or too many parts." );
102 return new self(
null,
null,
'' );
110 if ( $other instanceof
self ) {
112 $this->database === $other->database &&
113 $this->schema === $other->schema &&
114 $this->prefix === $other->prefix
118 return ( $this->
getId() === $other );
143 ( $this->database === $other->database || $this->database ===
null ) &&
144 ( $this->schema === $other->schema || $this->schema ===
null ) &&
145 $this->prefix === $other->prefix
155 $this->database ===
null && $this->schema ===
null && $this->prefix ===
''
184 if ( $this->equivalentString ===
null ) {
195 $parts = [ (
string)$this->database ];
196 if ( $this->schema !==
null ) {
199 if ( $this->prefix !=
'' || $this->schema !==
null ) {
208 return implode(
'-', array_map( [ __CLASS__,
'encode' ], $parts ) );
211 private static function encode( $decoded ) {
214 $length = strlen( $decoded );
215 for ( $i = 0; $i < $length; ++$i ) {
216 $char = $decoded[$i];
217 if ( $char ===
'-' ) {
219 } elseif ( $char ===
'?' ) {
229 private static function decode( $encoded ) {
232 $length = strlen( $encoded );
233 for ( $i = 0; $i < $length; ++$i ) {
234 $char = $encoded[$i];
235 if ( $char ===
'?' ) {
236 $nextChar = $encoded[$i + 1] ??
null;
237 if ( $nextChar ===
'h' ) {
240 } elseif ( $nextChar ===
'?' ) {
258 return $this->
getId();