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 has too few or too many parts." );
94 return new self(
null,
null,
'' );
104 $this->
database === $other->database &&
105 $this->schema === $other->schema &&
106 $this->prefix === $other->prefix
110 return ( $this->
getId() === $other );
138 if ( $this->equivalentString ===
null ) {
150 if ( $this->schema !==
null ) {
153 if ( $this->prefix !=
'' ) {
157 return implode(
'-', array_map( [ __CLASS__,
'encode' ], $parts ) );
160 private static function encode( $decoded ) {
163 $length = strlen( $decoded );
164 for ( $i = 0; $i < $length; ++$i ) {
165 $char = $decoded[$i];
166 if ( $char ===
'-' ) {
168 } elseif ( $char ===
'?' ) {
178 private static function decode( $encoded ) {
181 $length = strlen( $encoded );
182 for ( $i = 0; $i < $length; ++$i ) {
183 $char = $encoded[$i];
184 if ( $char ===
'?' ) {
185 $nextChar = isset( $encoded[$i + 1] ) ? $encoded[$i + 1] :
null;
186 if ( $nextChar ===
'h' ) {
189 } elseif ( $nextChar ===
'?' ) {
207 return $this->
getId();