Source for file Composite.php
Documentation is available at Composite.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* Copyright (c) 1997-2008 The PHP Group
* This source file is subject to version 3.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/3_01.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.
* @author Carsten Lucke <luckec@tool-garage.de>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version CVS: $Id: Composite.php,v 1.13 2008/01/26 00:08:34 kguest Exp $
* @link http://pear.php.net/package/Date_Holidays
define('DATE_HOLIDAYS_DRIVER_NOT_FOUND', 100 );
* Composite driver - you can use this one to combine two or more drivers
* @author Carsten Lucke <luckec@tool-garage.de>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version CVS: $Id: Composite.php,v 1.13 2008/01/26 00:08:34 kguest Exp $
* @link http://pear.php.net/package/Date_Holidays
* Driver-ids ordered by importance
var $_driverIds = array ();
* Use the Date_Holidays::factory() method to construct an object of a
* 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 $driver Date_Holidays_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 $driver Date_Holidays_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
* @return object Date_Holidays_Holiday holiday's information on
* success, otherwise a PEAR_Error
* @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
'Invalid internal name: ' . $internalName);
* 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
* @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
'Invalid internal name: ' . $internalName);
* Returns dates of all holidays or those accepted by the specified filter.
* @param Date_Holidays_Filter $filter filter-object
* (or an array !DEPRECATED!)
* @return array array with holidays' dates on success, otherwise a
* @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
$message = 'No date found for holiday with internal ' .
'name: ' . $internalName;
* current driver doesn't have this internalName, trying
* internal name found in highest priorized driver, stepping
* 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) {
'Invalid internal name: ' . $internalName,
if ($errorStack->hasErrors () && ! empty ($notFound)) {
* Returns the title of the holiday, if any was found, matching the
* Normally the method will return the title/data for the first holiday
* 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
* '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 true if multiple search is required.
* @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,
* No holiday found for this date in the current driver, trying
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 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
* 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) {
'Invalid internal name: ' . $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
* @throws object PEAR_Error 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
'Invalid internal name: ' . $internalName);
* Returns localized titles of all holidays or those specififed in
* @param Date_Holidays_Filter $filter filter-object
* (or an array !DEPRECATED!)
* @param string $locale locale setting that shall be used by
* @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,
* current driver doesn't have this internalName, trying next
* 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) {
'Invalid internal name: ' . $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
* 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 ) {
|