23use 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." );
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 = isset( $encoded[$i + 1] ) ? $encoded[$i + 1] :
null;
233 if ( $nextChar ===
'h' ) {
236 } elseif ( $nextChar ===
'?' ) {
254 return $this->
getId();
Class to handle database/prefix specification for IDatabase domains.
string $equivalentString
Cache of convertToString()
isCompatible( $other)
Check whether the domain $other meets the specifications of this domain.
static newFromId( $domain)
__construct( $database, $schema, $prefix)
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list