58 if ( $database !==
null && ( !is_string( $database ) || $database ===
'' ) ) {
59 throw new InvalidArgumentException(
'Database must be null or a non-empty string.' );
61 $this->database = $database;
62 if ( $schema !==
null && ( !is_string( $schema ) || $schema ===
'' ) ) {
63 throw new InvalidArgumentException(
'Schema must be null or a non-empty string.' );
64 } elseif ( $database ===
null && $schema !==
null ) {
65 throw new InvalidArgumentException(
'Schema must be null if database is null.' );
67 $this->schema = $schema;
68 if ( !is_string( $prefix ) ) {
69 throw new InvalidArgumentException(
"Prefix must be a string." );
71 $this->prefix = $prefix;
79 if ( $domain instanceof self ) {
83 if ( !is_string( $domain ) ) {
84 throw new InvalidArgumentException(
"Domain must be a string or " . __CLASS__ );
87 $parts = explode(
'-', $domain );
88 foreach ( $parts as &$part ) {
89 $part = strtr( $part, [
'?h' =>
'-',
'??' =>
'?' ] );
95 if ( count( $parts ) == 1 ) {
96 $database = $parts[0];
97 } elseif ( count( $parts ) == 2 ) {
98 [ $database, $prefix ] = $parts;
99 } elseif ( count( $parts ) == 3 ) {
100 [ $database, $schema, $prefix ] = $parts;
102 throw new InvalidArgumentException(
"Domain '$domain' has too few or too many parts." );
105 if ( $database ===
'' ) {
109 if ( $schema ===
'' ) {
113 $instance =
new self( $database, $schema, $prefix );
114 $instance->equivalentString = $domain;
157 if ( $this->isUnspecified() ) {
161 $other = self::newFromId( $other );
164 ( $this->database === $other->database || $this->database ===
null ) &&
165 ( $this->schema === $other->schema || $this->schema ===
null ) &&
166 $this->prefix === $other->prefix