Source for file Composite.php
Documentation is available at Composite.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: Composite.php,v 1.8 2006/04/01 17:15:31 schst Exp $
define('DATE_HOLIDAYS_DRIVER_NOT_FOUND', 100 );
* Composite driver - you can use this one to combine two or more drivers
* @version $Id: Composite.php,v 1.8 2006/04/01 17:15:31 schst Exp $
* @author Carsten Lucke <luckec@tool-garage.de>
* Driver-ids ordered by importance
var $_driverIds = array ();
* Use the Date_Holidays::factory() method to construct an object of a certain driver
* Build the internal arrays that contain data about the calculated holidays
* @return boolean true on success, otherwise a PEAR_ErrorStack object
* @throws object PEAR_ErrorStack
* @param object Date_Holidays_Driver $driver driver-object
* @return boolean true on success, false otherwise
if (! is_a($driver, 'Date_Holidays_Driver')) {
$this->_drivers[$id] = $driver;
* Remove a driver component
* @param object Date_Holidays_Driver $driver driver-object
* @return boolean true on success, otherwise a PEAR_Error object
* @throws object PEAR_Error DATE_HOLIDAYS_DRIVER_NOT_FOUND
if (! is_a($driver, 'Date_Holidays_Driver')) {
if (! isset ($this->_drivers[$id])) {
unset ($this->_drivers[$id]);
unset ($this->_driverIds[$index]);
// rebuild the internal-names array
foreach ($this->_driverIds as $id) {
* Returns the specified holiday
* 'title' => 'Easter Sunday'
* @param string $internalName internal name of the holiday
* @param string $locale locale setting that shall be used by this method
* @return object Date_Holidays_Holiday holiday's information on success, otherwise a PEAR_Error object
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME
function getHoliday($internalName, $locale = null )
foreach ($this->_driverIds as $id) {
$holiday = $this->_drivers[$id]->getHoliday ($internalName, $locale);
* lets skip this error, perhaps another driver knows this internal-name
* Returns date of a holiday
* @param string $internalName internal name for holiday
* @return object Date date of the holiday as PEAR::Date object on success, otherwise a PEAR_Error object
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME
foreach ($this->_driverIds as $id) {
$date = $this->_drivers[$id]->getHolidayDate ($internalName);
* lets skip this error, perhaps another driver knows this internal-name
* Returns dates of all holidays or those accepted by the specified filter.
* @param Date_Holidays_Filter filter-object (or an array !DEPRECATED!)
* @return array array with holidays' dates on success, otherwise a PEAR_ErrorStack object
* @throws object PEAR_ErrorStack DATE_HOLIDAYS_INVALID_INTERNAL_NAME
// check if the filter permits further processing
if (! $filter->accept ($internalName)) {
foreach ($this->_driverIds as $id) {
$date = $this->_drivers[$id]->getHolidayDate ($internalName);
* this means a fatal error (would be the right place for sth. like an assert,
* as this should normally never happen)
'No date found for holiday with internal name: ' . $internalName, false , debug_backtrace());
* current driver doesn't have this internalName, trying next driver
* internal name found in highest priorized driver, stepping to next internal name
* checks if internal name is existent in $notFound array and unsets this entry as it has been found now
if (in_array($internalName, $notFound)) {
$dates[$internalName] = $date;
if (! empty ($notFound)) {
foreach ($notFound as $internalName) {
if ($errorStack->hasErrors () && ! empty ($notFound)) {
* Returns the title of the holiday, if any was found, matching the specified date.
* Normally the method will return the title/data for the first holiday matching the date.
* If you want the mthod to continue searching holidays for the specified date, set the 4th param to true
* If multiple holidays match your date, the return value will be an array of the titles/data.
* 'date' => Object of type Date
* 'title' => 'Circumcision of Jesus',
* 'date' => Object of type Date
* @param mixed $date date (timestamp | string | PEAR::Date object)
* @param string $locale locale setting that shall be used by this method
* @param boolean $multiple
* @return object object of type Date_Holidays_Holiday on success (numeric array of those on multiple search); if no holiday was found, matching this date, null is returned
* @uses getHolidayTitle()
foreach ($this->_driverIds as $id) {
$holiday = $this->_drivers[$id]->getHolidayForDate ($date, $locale, $multiple);
* No holiday found for this date in the current driver, trying next one
for ($i = 0; $i < count($holiday); ++ $i) {
$holidays[] = $holiday[$i];
* Returns all holidays that were found
* 'title' => 'Easter Sunday'
* 'eastermonday' => array(
* 'title' => 'Easter Monday'
* @param Date_Holidays_Filter filter-object (or an array !DEPRECATED!)
* @return array numeric array containing objects of Date_Holidays_Holiday on success, otherwise a PEAR_ErrorStack object
* @throws object PEAR_ErrorStack DATE_HOLIDAYS_INVALID_INTERNAL_NAME
// check if the filter permits further processing
if (! $filter->accept ($internalName)) {
foreach ($this->_driverIds as $id) {
$holiday = $this->_drivers[$id]->getHoliday ($internalName);
* current driver doesn't have this internalName, trying next driver
* internal name found in highest priorized driver, stepping to next internal name
* checks if internal name is existent in $notFound array and unsets this entry as it has been found now
if (in_array($internalName, $notFound)) {
$holidays[$internalName] = $holiday;
if (! empty ($notFound)) {
foreach ($notFound as $internalName) {
if ($errorStack->hasErrors () && ! empty ($notFound)) {
* 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
* @return string title on success, otherwise a PEAR_Error object
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME, DATE_HOLIDAYS_TITLE_UNAVAILABLE
foreach ($this->_driverIds as $id) {
$title = $this->_drivers[$id]->getHolidayTitle ($internalName, $locale);
* lets skip this error, perhaps another driver knows this internal-name
* Returns localized titles of all holidays or those specififed in $restrict array
* @param Date_Holidays_Filter filter-object (or an array !DEPRECATED!)
* @param string $locale locale setting that shall be used by this method
* @return array array with localized holiday titles on success, otherwise a PEAR_Error object
* @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME
// check if the filter permits further processing
if (! $filter->accept ($internalName)) {
foreach ($this->_driverIds as $id) {
$title = $this->_drivers[$id]->getHolidayTitle ($internalName, $locale);
* current driver doesn't have this internalName, trying next driver
* internal name found in highest priorized driver, stepping to next internal name
* checks if internal name is existent in $notFound array and unsets this entry as it has been found now
if (in_array($internalName, $notFound)) {
$titles[$internalName] = $title;
if (! empty ($notFound)) {
foreach ($notFound as $internalName) {
if ($errorStack->hasErrors () && ! empty ($notFound)) {
* Using this method doesn't affect anything. If you have been able to add your driver to this compound,
* you should also be able to directly execute this action.
* This method is only available to keep abstraction working.
* This (re)sets the year of every driver-object in the compound.
* Note that this will cause every attached driver to recalculate the holidays!
* @return boolean true on success, otherwise a PEAR_ErrorStack object
* @throws object PEAR_ErrorStack
foreach ($this->_driverIds as $id) {
if ($this->_drivers[$id]->setYear ($year) != true ) {
* Determines whether a date represents a holiday or not.
* The method searches all added drivers for this date, to determine whether it's a holiday.
* @param mixed $date date (can be a timestamp, string or PEAR::Date object)
* @param Date_Holidays_Filter $filter filter-object (or an array !DEPRECATED!)
* @return boolean true if date represents a holiday, otherwise false
foreach ($this->_driverIds as $id) {
if ($this->_drivers[$id]->isHoliday ($date, $filter)) {
* Using this method doesn't affect anything. If you have bben able to add your driver to this compound,
* you should also be able to directly execute this action.
* This method is only available to keep abstraction working.
Documentation generated on Mon, 11 Mar 2019 15:03:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|