Yasumi\Holiday::__construct PHP Method

__construct() public method

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.
public __construct ( string $shortName, array $names, DateTime $date, string $displayLocale = self::DEFAULT_LOCALE, string $type = self::TYPE_NATIONAL )
$shortName string The short name (internal name) of this holiday
$names array An array containing the name/description of this holiday in various languages. Overrides global translations
$date DateTime A DateTime instance representing the date of the holiday
$displayLocale string Locale (i.e. language) in which the holiday information needs to be displayed in. (Default 'en_US')
$type string 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.
    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());
    }