/** * Creates a new Holiday. * * If a holiday date needs to be defined for a specific timezone, make sure that the date instance (DateTime) has * the correct timezone set. Otherwise the default system timezone is used. * * @param string $shortName The short name (internal name) of this holiday * @param array $names An array containing the name/description of this holiday in various * languages. Overrides global translations * @param DateTime $date A DateTime instance representing the date of the holiday * @param string $displayLocale Locale (i.e. language) in which the holiday information needs to be * displayed in. (Default 'en_US') * @param string $type The type of holiday. Use the following constants: TYPE_NATIONAL, * TYPE_OBSERVANCE, TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default a * national holiday is considered. * * @throws UnknownLocaleException */ public function __construct($shortName, array $names, $date, $displayLocale = self::DEFAULT_LOCALE, $type = self::TYPE_NATIONAL) { // Validate if short name is not empty if (empty($shortName)) { throw new InvalidArgumentException('Holiday name can not be blank.'); } // Validate if date parameter is instance of DateTime if (!$date instanceof DateTime) { throw new InvalidArgumentException(sprintf('Date "%s" is not a valid DateTime instance.', $date)); } // Load internal locales variable if (!isset(static::$locales)) { static::$locales = Yasumi::getAvailableLocales(); } // Assert display locale input if (!in_array($displayLocale, static::$locales)) { throw new UnknownLocaleException(sprintf('Locale "%s" is not a valid locale.', $displayLocale)); } // Set additional attributes $this->shortName = $shortName; $this->translations = $names; $this->displayLocale = $displayLocale; $this->type = $type; // Construct instance parent::__construct($date->format('Y-m-d'), $date->getTimezone()); }