code = $bcp47code; } /** @inheritDoc */ public function toBcp47Code(): string { return $this->code; } /** @inheritDoc */ public function isSameCodeAs( Bcp47Code $other ): bool { return ( $this === $other ) || self::isSameCode( $this, $other ); } public function __toString() { return $this->toBcp47Code(); } /** * Simple helper to coerce any Bcp47Code into a Bcp47CodeValue. * @param Bcp47Code $language an object representing a language * @return Bcp47CodeValue a simple value object representing a language. */ public static function fromBcp47Code( Bcp47Code $language ): Bcp47CodeValue { if ( $language instanceof Bcp47CodeValue ) { return $language; } return new Bcp47CodeValue( $language->toBcp47Code() ); } /** * Simple helper to compare Bcp47Code in the proper case-insensitive * manner. * @param Bcp47Code $a * @param Bcp47Code $b * @return bool True if the bcp-47 codes should be considered equal */ public static function isSameCode( Bcp47Code $a, Bcp47Code $b ) { return ( $a === $b ) || strcasecmp( $a->toBcp47Code(), $b->toBcp47Code() ) === 0; } }