23 use InvalidArgumentException;
58 throw new InvalidArgumentException(
'Database must be null or a non-empty string.' );
62 throw new InvalidArgumentException(
'Schema must be null or a non-empty string.' );
64 throw new InvalidArgumentException(
'Schema must be null if database is null.' );
68 throw new InvalidArgumentException(
"Prefix must be a string." );
78 if ( $domain instanceof
self ) {
82 $parts = array_map( [ __CLASS__,
'decode' ], explode(
'-', $domain ) );
87 if ( count( $parts ) == 1 ) {
89 } elseif ( count( $parts ) == 2 ) {
91 } elseif ( count( $parts ) == 3 ) {
94 throw new InvalidArgumentException(
"Domain '$domain' has too few or too many parts." );
106 $instance->equivalentString = (string)$domain;
115 return new self(
null,
null,
'' );
123 if ( $other instanceof
self ) {
125 $this->database === $other->database &&
126 $this->schema === $other->schema &&
127 $this->prefix === $other->prefix
131 return ( $this->
getId() === $other );
156 ( $this->database === $other->database || $this->database ===
null ) &&
157 ( $this->schema === $other->schema || $this->schema ===
null ) &&
158 $this->prefix === $other->prefix
168 $this->database ===
null && $this->schema ===
null && $this->prefix ===
''
197 if ( $this->equivalentString ===
null ) {
208 $parts = [ (string)$this->database ];
209 if ( $this->schema !==
null ) {
212 if ( $this->prefix !=
'' || $this->schema !==
null ) {
221 return implode(
'-', array_map( [ __CLASS__,
'encode' ], $parts ) );
224 private static function encode( $decoded ) {
227 $length = strlen( $decoded );
228 for ( $i = 0; $i < $length; ++$i ) {
229 $char = $decoded[$i];
230 if ( $char ===
'-' ) {
232 } elseif ( $char ===
'?' ) {
242 private static function decode( $encoded ) {
245 $length = strlen( $encoded );
246 for ( $i = 0; $i < $length; ++$i ) {
247 $char = $encoded[$i];
248 if ( $char ===
'?' ) {
249 $nextChar = $encoded[$i + 1] ??
null;
250 if ( $nextChar ===
'h' ) {
253 } elseif ( $nextChar ===
'?' ) {
271 return $this->
getId();