public function __construct($countryCode, CountryCode $countryCodeRule = null) { $countryCodeRule = $countryCodeRule ?: new CountryCode(); if (!$countryCodeRule->validate($countryCode)) { throw new ComponentException(sprintf('Cannot validate postal code from "%s" country', $countryCode)); } $regex = self::DEFAULT_PATTERN; $upperCountryCode = strtoupper($countryCode); if (isset($this->postalCodes[$upperCountryCode])) { $regex = $this->postalCodes[$upperCountryCode]; } parent::__construct($regex); }
public function __construct($countryCode) { if (!isset($this->postalCodes[$countryCode])) { throw new ComponentException(sprintf('Cannot validate postal code from "%s" country', $countryCode)); } parent::__construct($this->postalCodes[$countryCode]); }