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." );
66 if ( $domain instanceof
self ) {
70 $parts = array_map( [ __CLASS__,
'decode' ], explode(
'-', $domain ) );
75 if (
count( $parts ) == 1 ) {
77 } elseif (
count( $parts ) == 2 ) {
79 } elseif (
count( $parts ) == 3 ) {
82 throw new InvalidArgumentException(
"Domain '$domain' has too few or too many parts." );
100 return new self(
null,
null,
'' );
108 if ( $other instanceof
self ) {
110 $this->database === $other->database &&
111 $this->schema === $other->schema &&
112 $this->prefix === $other->prefix
116 return ( $this->
getId() === $other );
141 ( $this->database === $other->database || $this->database ===
null ) &&
142 ( $this->schema === $other->schema || $this->schema ===
null ) &&
143 $this->prefix === $other->prefix
153 $this->database ===
null && $this->schema ===
null && $this->prefix ===
''
182 if ( $this->equivalentString ===
null ) {
193 $parts = [ (
string)$this->database ];
194 if ( $this->schema !==
null ) {
197 if ( $this->prefix !=
'' || $this->schema !==
null ) {
206 return implode(
'-', array_map( [ __CLASS__,
'encode' ], $parts ) );
209 private static function encode( $decoded ) {
212 $length = strlen( $decoded );
213 for ( $i = 0; $i < $length; ++$i ) {
214 $char = $decoded[$i];
215 if ( $char ===
'-' ) {
217 } elseif ( $char ===
'?' ) {
227 private static function decode( $encoded ) {
230 $length = strlen( $encoded );
231 for ( $i = 0; $i < $length; ++$i ) {
232 $char = $encoded[$i];
233 if ( $char ===
'?' ) {
234 $nextChar = $encoded[$i + 1] ??
null;
235 if ( $nextChar ===
'h' ) {
238 } elseif ( $nextChar ===
'?' ) {
256 return $this->
getId();