/** * Factory method that creates a driver-object * * @param string $isoCode ISO3166 code identifying the driver * @param string $year year * @param string $locale locale name * @param boolean $external external driver * * @static * @access public * @return object Date_Holidays driver-object on success, otherwise * a PEAR_Error object * @throws object PEAR_Error */ function factoryISO3166($isoCode, $year = null, $locale = null, $external = false) { $driverDir = dirname(__FILE__) . '/Holidays/Driver'; if (!is_dir($driverDir)) { return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND, 'Date_Holidays driver directory does not exist'); } $driverMappings = array(); $driverFiles = array(); $dh = opendir($driverDir); while (false !== ($filename = readdir($dh))) { array_push($driverFiles, $filename); } foreach ($driverFiles as $driverFileName) { $file = dirname(__FILE__) . '/Holidays/Driver/' . $driverFileName; if (!is_file($file)) { continue; } $driverId = str_replace('.php', '', $driverFileName); $driverClass = 'Date_Holidays_Driver_' . $driverId; $driverFilePath = $driverDir . '/' . $driverFileName; @(include_once $driverFilePath); if (!class_exists($driverClass)) { return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND, 'Couldn\'t find file of the driver-class ' . $driverClass . ', filename: ' . $driverFilePath); } $isoCodes = call_user_func(array($driverClass, DATE_HOLIDAYS_DRIVER_IDENTIFY_ISO3166_METHOD)); foreach ($isoCodes as $code) { if (strtolower($code) === $isoCode) { return Date_Holidays::factory($driverId, $year, $locale, $external); } } } /* * If this line is reached the iso-code couldn't be mapped to * a driver-class and an error will be thrown. */ return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND, 'Couldn\'t find a driver for the given ISO 3166 code: ' . $isoCode); }
/** * Remove a filter from the compound. * * @param Date_Holidays_Filter $filter filter object * * @access public * @return boolean true on success, otherwise a PEAR_Error object * @throws PEAR_Error DATE_HOLIDAYS_FILTER_NOT_FOUND */ function removeFilter($filter) { if (!is_a($filter, 'Date_Holidays_Filter')) { return false; } $id = md5(serialize($filter)); // unset filter object if (!isset($this->_filters[$id])) { return Date_Holidays::raiseError(DATE_HOLIDAYS_FILTER_NOT_FOUND, 'Filter not found'); } unset($this->_drivers[$id]); return true; }
/** * Returns date of a holiday * * @param string $internalName internal name for holiday * * @access public * @return object Date date of holiday as PEAR::Date object * on success, otherwise a PEAR_Error object * @throws object PEAR_Error DATE_HOLIDAYS_DATE_UNAVAILABLE * @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME */ function getHolidayDate($internalName) { if (!in_array($internalName, $this->_internalNames)) { $msg = 'Invalid internal name: ' . $internalName; return Date_Holidays::raiseError(DATE_HOLIDAYS_INVALID_INTERNAL_NAME, $msg); } if (!isset($this->_dates[$internalName])) { $msg = 'Date for holiday with internal name ' . $internalName . ' is not available'; return Date_Holidays::raiseError(DATE_HOLIDAYS_DATE_UNAVAILABLE, $msg); } return $this->_dates[$internalName]; }
/** * Returns localized title for a holiday * * @param string $internalName internal name for holiday * @param string $locale locale setting that shall be used by this method * * @access public * @return string title on success, otherwise a PEAR_Error object * @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME * @throws object PEAR_Error DATE_HOLIDAYS_TITLE_UNAVAILABLE */ function getHolidayTitle($internalName, $locale = null) { foreach ($this->_driverIds as $id) { $title = $this->_drivers[$id]->getHolidayTitle($internalName, $locale); if (Date_Holidays::isError($title)) { /** * lets skip this error, perhaps another driver knows this * internal-name */ continue; } return $title; } return Date_Holidays::raiseError(DATE_HOLIDAYS_INVALID_INTERNAL_NAME, 'Invalid internal name: ' . $internalName); }