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." );
54 throw new InvalidArgumentException(
"Prefix must be a string." );
64 if ( $domain instanceof
self ) {
68 $parts = array_map( [ __CLASS__,
'decode' ], explode(
'-', $domain ) );
73 if (
count( $parts ) == 1 ) {
75 } elseif (
count( $parts ) == 2 ) {
77 } elseif (
count( $parts ) == 3 ) {
80 throw new InvalidArgumentException(
"Domain '$domain' has too few or too many parts." );
98 return new self(
null,
null,
'' );
106 if ( $other instanceof
self ) {
108 $this->database === $other->database &&
109 $this->schema === $other->schema &&
110 $this->prefix === $other->prefix
114 return ( $this->
getId() === $other );
136 $other = ( $other instanceof self ) ? $other : self::newFromId( $other );
139 ( $this->database === $other->database || $this->database ===
null ) &&
140 ( $this->schema === $other->schema || $this->schema === null ) &&
141 $this->prefix === $other->prefix
151 $this->database ===
null && $this->schema ===
null && $this->prefix ===
''
180 if ( $this->equivalentString ===
null ) {
192 if ( $this->schema !==
null ) {
195 if ( $this->prefix !=
'' || $this->schema !==
null ) {
204 return implode(
'-', array_map( [ __CLASS__,
'encode' ], $parts ) );
207 private static function encode( $decoded ) {
210 $length = strlen( $decoded );
211 for ( $i = 0; $i < $length; ++$i ) {
212 $char = $decoded[$i];
213 if ( $char ===
'-' ) {
215 } elseif ( $char ===
'?' ) {
225 private static function decode( $encoded ) {
228 $length = strlen( $encoded );
229 for ( $i = 0; $i < $length; ++$i ) {
230 $char = $encoded[$i];
231 if ( $char ===
'?' ) {
232 $nextChar = $encoded[$i + 1] ??
null;
233 if ( $nextChar ===
'h' ) {
236 } elseif ( $nextChar ===
'?' ) {
254 return $this->
getId();