Source for file Holidays.php
Documentation is available at Holidays.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* Copyright (c) 1997-2008 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>
* @author Carsten Lucke <luckec@tool-garage.de>
* @author Stephan Schmidt <schst@php.net>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @link http://pear.php.net/package/Date_Holidays
* 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
* @author Carsten Lucke <luckec@tool-garage.de>
* @author Stephan Schmidt <schst@php.net>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @link http://pear.php.net/package/Date_Holidays
* Use the Date_Holidays::factory() method to construct an object of
* Factory method that creates a driver-object
* @param string $driverId driver-name
* @param string $year year
* @param string $locale locale name
* @param boolean $external external driver
* @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/Holidays/Driver/' . $driverId . '.php';
$driverFile = str_replace('_', '/', $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);
//encoding might be appended to the locale, For example en_IE.UTF-8
$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
* @param boolean $external external driver
* @return object Date_Holidays driver-object on success, otherwise
* @throws object PEAR_Error
$driverDir = dirname(__FILE__ ) . '/Holidays/Driver';
'Date_Holidays driver directory does not exist');
$driverMappings = array ();
while (false !== ($filename = readdir($dh))) {
foreach ($driverFiles as $driverFileName) {
$file = dirname(__FILE__ ) . '/Holidays/Driver/' . $driverFileName;
$driverClass = 'Date_Holidays_Driver_' . $driverId;
$driverFilePath = $driverDir . '/' . $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';
$msg = 'The driver directory "'. $directory. '" does not exist';
* Returns a list of the installed filters
* @param string $directory where the filters are installed
if ($directory === null ) {
$directory = dirname(__FILE__ ) . '/Holidays/Filter';
$msg = 'The filter directory "'. $directory. '" does not exist';
* Fetch all modules from a directory and its subdirectories
* @param string $directory specified directory
* @param string $prefix for the class names, will be used in recursive calls
while (false !== $moduleFile = $d->read ()) {
if ($moduleFile === '.' ||
if (is_dir($directory. '/'. $moduleFile)) {
$prefix. $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,
* Checks a variable to determine whether it represents 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 then 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 Tue, 22 Jan 2013 01:00:09 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|