Source for file Holidays.php
Documentation is available at Holidays.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Carsten Lucke <luckec@tool-garage.de> |
// +----------------------------------------------------------------------+
// $Id: Holidays.php,v 1.13 2007/05/28 14:52:56 luckec Exp $
* Class that wraps a holiday's data
require_once 'Date/Holidays/Holiday.php';
require_once 'Date/Holidays/Driver.php';
* could not find file of driver-class
define('DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND', 1 );
* invalid argument was passed to a method
define('DATE_HOLIDAYS_ERROR_INVALID_ARGUMENT', 2 );
* Driver directory does not exist
define('DATE_HOLIDAYS_ERROR_MISSING_DRIVER_DIR', 3 );
* Filter directory does not exist
define('DATE_HOLIDAYS_ERROR_MISSING_FILTER_DIR', 4 );
* class that helps you to locate holidays for a year
* @version $Id: Holidays.php,v 1.13 2007/05/28 14:52:56 luckec Exp $
* @author Carsten Lucke <luckec@tool-garage.de>
* @author Stephan Schmidt <schst@php.net>
* Use the Date_Holidays::factory() method to construct an object of a certain driver
* Factory method that creates a driver-object
* @param string $driverId driver-name
* @param string $year year
* @param string $locale locale name
* @return object Date_Holidays driver-object on success, otherwise a PEAR_Error object
* @throws object PEAR_Error
function factory($driverId, $year = null , $locale = null , $external = false )
if (! isset ($GLOBALS['_DATE_HOLIDAYS']['DIE_ON_MISSING_LOCALE'])) {
$driverClass = 'Date_Holidays_Driver_' . $driverId;
$driverClass = $driverId;
$driverFile = 'Date' . DIRECTORY_SEPARATOR . 'Holidays' . DIRECTORY_SEPARATOR .
'Driver' . DIRECTORY_SEPARATOR . $driverId . '.php';
$driverFile = str_replace('_', DIRECTORY_SEPARATOR , $driverClass) . '.php';
@include_once $driverFile;
'Couldn\'t find file of the driver-class, filename: ' . $driverFile);
$driver = new $driverClass;
// sets internal var $_year and performs _buildHolidays()
$res = $driver->setYear ($year);
$driver->setLocale ($locale);
* Factory method that creates a driver-object
* @param string $isoCode ISO3166 code identifying the driver
* @param string $year year
* @param string $locale locale name
* @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__ ) . DIRECTORY_SEPARATOR . 'Holidays' . DIRECTORY_SEPARATOR . 'Driver';
'Date_Holidays driver directory does not exist');
$driverMappings = array ();
while (false !== ($filename = readdir($dh))) {
foreach ($driverFiles as $driverFileName) {
$file = dirname(__FILE__ ) . DIRECTORY_SEPARATOR . 'Holidays'
. DIRECTORY_SEPARATOR . 'Driver'
. DIRECTORY_SEPARATOR . $driverFileName;
$driverClass = 'Date_Holidays_Driver_' . $driverId;
$driverFilePath = $driverDir . DIRECTORY_SEPARATOR . $driverFileName;
@include_once $driverFilePath;
'Couldn\'t find file of the driver-class ' . $driverClass
. ', filename: ' . $driverFilePath);
foreach ($isoCodes as $code) {
* If this line is reached the iso-code couldn't be mapped to
* a driver-class and an error will be thrown.
'Couldn\'t find a driver for the given ISO 3166 code: ' . $isoCode);
* Returns a list of the installed drivers
* @param string directory, where the drivers are installed
if ($directory === null ) {
$directory = dirname(__FILE__ ) . '/Holidays/Driver';
* Returns a list of the installed filters
* @param string directory, where the filters are installed
if ($directory === null ) {
$directory = dirname(__FILE__ ) . '/Holidays/Filter';
* Fetch all modules from a directory and its subdirectories
* @param string directory
* @param string prefix for the class names, will be used in recursive calls
while (false !== $moduleFile = $d->read ()) {
if ($moduleFile === '.' || $moduleFile === '..' || $moduleFile === 'CVS') {
if (is_dir($dir. '/'. $moduleFile)) {
if (preg_match('/(.*)\.php$/', $moduleFile, $matches)) {
array_push($modules, array ('id' => $prefix. $matches[1 ], 'title' => $prefix. $matches[1 ]));
* Returns the error-stack
* @return object PEAR_ErrorStack error-stack
return PEAR_ErrorStack ::singleton ('Date_Holidays', false , false , true );
* Pushes a new error on the error-stack and returns a PEAR_Error object
* @param int $code error-code
* @param string $msg error-message
* @return object PEAR_Error
return $errorStack->push ($code, 'error', array (), $msg, false , debug_backtrace());
* Checks a variable to determine whether it represnts an error object or not
* @param mixed $data variable to test
* @param int $code if $data is an PEAR_Error object, return true
* only if $code is a string and
* $obj->getMessage() == $code or
* $code is an integer and $obj->getCode() == $code
* @return boolean true if $subject is an error object
function isError($data, $code = null )
return PEAR ::isError ($data, $code);
return $data->hasErrors ();
* Checks whether errors occured
* @return boolean true if errors occurred
return $errorStack->hasErrors ();
* Returns the errors the error-stack contains
* @param boolean $purge true if the stall shall be purged
return $errorStack->getErrors ($purge);
* Set a property for the Date_Holidays drivers
* DIE_ON_MISSING_LOCALE = boolean
* false: if no localized holiday-title is found an error will be returned
* true: if no localized holiday-title is found the default translation (English) will be used
* @param string $prop property
* @param string $value property-value
if (! isset ($GLOBALS['_DATE_HOLIDAYS'])) {
$GLOBALS['_DATE_HOLIDAYS'] = array ();
case 'DIE_ON_MISSING_LOCALE':
$GLOBALS['_DATE_HOLIDAYS'][$prop] = $value;
* Returns an internal property value
* @param string $prop property-name
* @return mixed property value on success, otherwise null
if (! isset ($GLOBALS['_DATE_HOLIDAYS'])) {
case 'DIE_ON_MISSING_LOCALE':
if (isset ($GLOBALS['_DATE_HOLIDAYS'][$prop])) {
return $GLOBALS['_DATE_HOLIDAYS'][$prop];
Documentation generated on Mon, 11 Mar 2019 15:03:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|