Date_Holidays
[ class tree: Date_Holidays ] [ index: Date_Holidays ] [ all elements ]

Source for file Driver.php

Documentation is available at Driver.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors:   Carsten Lucke <luckec@tool-garage.de>                     |
  17. // +----------------------------------------------------------------------+
  18. //
  19. //    $Id: Driver.php,v 1.7 2005/02/13 21:51:47 luckec Exp $s
  20.  
  21. /**
  22.  * uses PEAR_Errorstack
  23.  */
  24. require_once 'PEAR/ErrorStack.php';
  25. require_once 'Date/Holidays/Filter.php';
  26. require_once 'Date/Holidays/Filter/Whitelist.php';
  27. require_once 'Date/Holidays/Filter/Blacklist.php';
  28.  
  29. /**
  30.  * invalid internal name
  31.  *
  32.  * @access  public
  33.  */
  34. define('DATE_HOLIDAYS_INVALID_INTERNAL_NAME'51);
  35.  
  36. /**
  37.  * title for a holiday is not available
  38.  *
  39.  * @access  public
  40.  */
  41. define('DATE_HOLIDAYS_TITLE_UNAVAILABLE'52);
  42.  
  43. /**
  44.  * date could not be converted into a PEAR::Date object
  45.  *
  46.  * date was neither a timestamp nor a string
  47.  *
  48.  * @access  public
  49.  * @deprecated   will certainly be removed
  50.  */
  51. define('DATE_HOLIDAYS_INVALID_DATE'53);
  52.  
  53. /**
  54.  * string that represents a date has wrong format
  55.  *
  56.  * format must be YYYY-MM-DD
  57.  *
  58.  * @access  public
  59.  * @deprecated   will certainly be removed
  60.  */
  61. define('DATE_HOLIDAYS_INVALID_DATE_FORMAT'54);
  62.  
  63. /**
  64.  * date for a holiday is not available
  65.  *
  66.  * @access  public
  67.  */
  68. define('DATE_HOLIDAYS_DATE_UNAVAILABLE'55);
  69.  
  70. /**
  71.  * language-file doesn't exist
  72.  *
  73.  * @access  public
  74.  */
  75. define('DATE_HOLIDAYS_LANGUAGEFILE_NOT_FOUND'56);
  76.  
  77. /**
  78.  * class that helps you to locate holidays for a year
  79.  *
  80.  * @abstract
  81.  * @category    Date
  82.  * @package     Date_Holidays
  83.  * @subpackage  Driver
  84.  * @version     $Id: Driver.php,v 1.7 2005/02/13 21:51:47 luckec Exp $
  85.  * @author      Carsten Lucke <luckec@tool-garage.de>
  86.  */
  87. {
  88.    /**
  89.     * locale setting for output
  90.     *
  91.     * @access   protected
  92.     * @var      string 
  93.     */
  94.     var $_locale;
  95.     
  96.    /**
  97.     * locales for which translations of holiday titles are available
  98.     *
  99.     * @access   private
  100.     * @var      array 
  101.     */
  102.     var $_availableLocales = array('C');
  103.     
  104.    /**
  105.     * object's current year
  106.     *
  107.     * @access   protected
  108.     * @var      int 
  109.     */
  110.     var $_year;
  111.     
  112.    /**
  113.     * internal names for the available holidays
  114.     *
  115.     * @access   protected
  116.     * @var      array 
  117.     */
  118.     var $_internalNames = array();
  119.     
  120.    /**
  121.     * dates of the available holidays
  122.     *
  123.     * @access   protected
  124.     * @var      array 
  125.     */
  126.     var $_dates = array();
  127.     
  128.    /**
  129.     * array of the available holidays indexed by date
  130.     *
  131.     * @access   protected
  132.     * @var      array 
  133.     */
  134.     var $_holidays = array();
  135.  
  136.    /**
  137.     * localized names of the available holidays
  138.     *
  139.     * @access   protected
  140.     * @var      array 
  141.     */
  142.     var $_titles = array();
  143.     
  144.    /**
  145.     * Constructor
  146.     *
  147.     * Use the Date_Holidays::factory() method to construct an object of a certain driver
  148.     *
  149.     * @access   protected
  150.     */
  151.     function Date_Holidays_Driver()
  152.     {
  153.     }
  154.     
  155.    /**
  156.     * Sets the driver's current year
  157.     *
  158.     * Calling this method forces the object to rebuild the holidays
  159.     *
  160.     * @access   public
  161.     * @param    int     $year   year
  162.     * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  163.     * @throws   object PEAR_ErrorStack
  164.     * @uses     _buildHolidays()
  165.     */
  166.     function setYear($year)
  167.     {
  168.         $this->_year    =   $year;
  169.         return $this->_buildHolidays();
  170.     }
  171.     
  172.    /**
  173.     * Returns the driver's current year
  174.     *
  175.     * @access   public
  176.     * @return   int     current year
  177.     */
  178.     function getYear()
  179.     {
  180.         return $this->_year;
  181.     }
  182.     
  183.    /**
  184.     * Build the internal arrays that contain data about the calculated holidays
  185.     *
  186.     * @abstract
  187.     * @access   protected
  188.     * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  189.     * @throws   object PEAR_ErrorStack
  190.     */
  191.     function _buildHolidays()
  192.     {
  193.     }
  194.     
  195.    /**
  196.     * Add a driver component
  197.     *
  198.     *
  199.     *
  200.     * @abstract
  201.     * @access   public
  202.     * @param    object Date_Holidays_Driver $driver driver-object
  203.     */
  204.     function addDriver($driver)
  205.     {
  206.     }
  207.     
  208.    /**
  209.     * Remove a driver component
  210.     *
  211.     * @abstract
  212.     * @access   public
  213.     * @param    object Date_Holidays_Driver $driver driver-object
  214.     * @return   boolean true on success, otherwise a PEAR_Error object
  215.     * @throws   object PEAR_Error   DATE_HOLIDAYS_DRIVER_NOT_FOUND
  216.     */
  217.     function removeDriver($driver)
  218.     {
  219.     }
  220.     
  221.    /**
  222.     * Returns the internal names of holidays that were calculated
  223.     *
  224.     * @access   public
  225.     * @return   array 
  226.     */
  227.     function getInternalHolidayNames()
  228.     {
  229.         return $this->_internalNames;
  230.     }
  231.     
  232.    /**
  233.     * Returns localized titles of all holidays or those specififed in $restrict array
  234.     *
  235.     * @access   public
  236.     * @param    Date_Holidays_Filter    filter-object (or an array !DEPRECATED!)
  237.     * @param    string  $locale         locale setting that shall be used by this method
  238.     * @return   array   array with localized holiday titles on success, otherwise a PEAR_Error object
  239.     * @throws   object PEAR_Error   DATE_HOLIDAYS_INVALID_INTERNAL_NAME
  240.     * @uses     getHolidayTitle()
  241.     */
  242.     function getHolidayTitles($filter = null$locale = null)
  243.     {
  244.         if (is_null($filter)) {
  245.             $filter &new Date_Holidays_Filter_Blacklist(array());
  246.         elseif (is_array($filter)) {
  247.             $filter &new Date_Holidays_Filter_Whitelist($filter);
  248.         }
  249.         
  250.         $titles =   array();
  251.         
  252.         foreach ($this->_internalNames as $internalName{
  253.             if ($filter->accept($internalName)) {
  254.                 $title $this->getHolidayTitle($internalName$locale);
  255.                 if (Date_Holidays::isError($title)) {
  256.                     return $title;
  257.                 }
  258.                 $titles[$internalName$title;
  259.             }
  260.         }
  261.         
  262.         return $titles;
  263.     }
  264.     
  265.    /**
  266.     * Returns localized title for a holiday
  267.     *
  268.     * @access   public
  269.     * @param    string  $internalName   internal name for holiday
  270.     * @param    string  $locale         locale setting that shall be used by this method
  271.     * @return   string  title on success, otherwise a PEAR_Error object
  272.     * @throws   object PEAR_Error   DATE_HOLIDAYS_INVALID_INTERNAL_NAME, DATE_HOLIDAYS_TITLE_UNAVAILABLE
  273.     */
  274.     function getHolidayTitle($internalName$locale = null)
  275.     {
  276.         if (in_array($internalName$this->_internalNames)) {
  277.             return Date_Holidays::raiseError(DATE_HOLIDAYS_INVALID_INTERNAL_NAME'Invalid internal name: ' $internalName);
  278.         }
  279.         
  280.         if (is_null($locale)) {
  281.             $locale =   $this->_findBestLocale($this->_locale);
  282.         else {
  283.             $locale =   $this->_findBestLocale($locale);
  284.         }
  285.         
  286.         if (isset($this->_titles[$locale][$internalName])) {
  287.             if (Date_Holidays::staticGetProperty('DIE_ON_MISSING_LOCALE')) {
  288.                 return Date_Holidays::raiseError(DATE_HOLIDAYS_TITLE_UNAVAILABLE'The internal name (' $internalName 
  289.                     ') for the holiday was correct but no localized title could be found');
  290.             }
  291.         }
  292.  
  293.         return isset($this->_titles[$locale][$internalName]
  294.             $this->_titles[$locale][$internalName$this->_titles['C'][$internalName];
  295.     }
  296.     
  297.    /**
  298.     * Returns all holidays that the driver knows.
  299.     *
  300.     * You can limit the holidays by setting the $restrict array, then only those
  301.     * will be returned, whose internal name occurrs in this array.
  302.     *
  303.     * Return format:
  304.     * <pre>
  305.     *   array(
  306.     *       'easter'        =>  object of type Date_Holidays_Holiday,
  307.     *       'eastermonday'  =>  object of type Date_Holidays_Holiday,
  308.     *       ...
  309.     *   )
  310.     * </pre>
  311.     *
  312.     * @access   public
  313.     * @param    Date_Holidays_Filter    filter-object (or an array !DEPRECATED!)
  314.     * @return   array   numeric array containing objects of Date_Holidays_Holiday on success, otherwise a PEAR_Error object
  315.     * @throws   object PEAR_Error   DATE_HOLIDAYS_INVALID_INTERNAL_NAME
  316.     * @see      getHoliday()
  317.     * @uses     getHoliday()
  318.     */
  319.     function getHolidays($filter = null)
  320.     {
  321.         if (is_null($filter)) {
  322.             $filter &new Date_Holidays_Filter_Blacklist(array());
  323.         elseif (is_array($filter)) {
  324.             $filter &new Date_Holidays_Filter_Whitelist($filter);
  325.         }
  326.         
  327.         $holidays       = array();
  328.         
  329.         foreach ($this->_internalNames as $internalName{
  330.             if ($filter->accept($internalName)) {
  331.                 if (in_array($internalName$this->_internalNames)) {
  332.                     return Date_Holidays::raiseError(DATE_HOLIDAYS_INVALID_INTERNAL_NAME
  333.                             'Invalid internal name: ' $internalName);
  334.                 }
  335.                 $holidays[$internalName&$this->getHoliday($internalName);
  336.             }
  337.         }
  338.         
  339.         return $holidays;
  340.     }
  341.     
  342.    /**
  343.     * Returns the specified holiday
  344.     *
  345.     * Return format:
  346.     * <pre>
  347.     *   array(
  348.     *       'title' =>  'Easter Sunday'
  349.     *       'date'  =>  '2004-04-11'
  350.     *   )
  351.     * </pre>
  352.     *
  353.     * @access   public
  354.     * @param    string  $internalName   internal name of the holiday
  355.     * @param    string  $locale         locale setting that shall be used by this method
  356.     * @return   object Date_Holidays_Holiday    holiday's information on success, otherwise a PEAR_Error object
  357.     * @throws   object PEAR_Error       DATE_HOLIDAYS_INVALID_INTERNAL_NAME
  358.     * @uses     getHolidayTitle()
  359.     * @uses     getHolidayDate()
  360.     */
  361.     function getHoliday($internalName$locale = null)
  362.     {
  363.         if (in_array($internalName$this->_internalNames)) {
  364.                 'Invalid internal name: ' $internalName);
  365.         }
  366.         if (is_null($locale)) {
  367.             $locale $this->_locale;
  368.         }
  369.         
  370.         $title      $this->getHolidayTitle($internalName$locale);
  371.         if (Date_Holidays::isError($title)) {
  372.             return $title;
  373.         }
  374.         $date       &$this->getHolidayDate($internalName);
  375.         if (Date_Holidays::isError($date)) {
  376.             return $date;
  377.         }
  378.         
  379.         return new Date_Holidays_Holiday($internalName$title$date);
  380.     }
  381.     
  382.    /**
  383.     * Determines whether a date represents a holiday or not
  384.     *
  385.     * @access   public
  386.     * @param    mixed   $date       date (can be a timestamp, string or PEAR::Date object)
  387.     * @param    array   $restrict   internal-names of holidays to limit search on
  388.     * @return   boolean true if date represents a holiday, otherwise false
  389.     * @throws   object PEAR_Error   DATE_HOLIDAYS_INVALID_DATE, DATE_HOLIDAYS_INVALID_DATE_FORMAT
  390.     */
  391.     function isHoliday($date$restrict = array())
  392.     {
  393.         if (is_a($date'Date')) {
  394.             $date   =$this->_convertDate($date);
  395.             if (Date_Holidays::isError($date)) {
  396.                 return $date;
  397.             }
  398.         }
  399.  
  400.         if (empty($restrict)) {
  401.             $restrict $this->_internalNames;
  402.         }
  403.         
  404.         foreach (array_keys($this->_datesas $internalName{
  405.             if (in_array($internalName$restrict)) {
  406.                 if ($date->compare($date$this->_dates[$internalName]!= 0{
  407.                     continue;
  408.                 }
  409.                 return true;
  410.             }
  411.         }
  412.         return false;
  413.     }
  414.     
  415.    /**
  416.     * Returns the title of the holiday, if any was found, matching the specified date.
  417.     *
  418.     * Normally the method will return the title/data for the first holiday matching the date.
  419.     * If you want the mthod to continue searching holidays for the specified date, set the 4th param to true
  420.     * If multiple holidays match your date, the return value will be an array of the titles/data.
  421.     * <pre>
  422.     * array(
  423.     *   array(
  424.     *       'title' => 'New Year',
  425.     *       'date'  => Object of type Date
  426.     *   ),
  427.     *   array(
  428.     *       'title' => 'Circumcision of Jesus',
  429.     *       'date'  => Object of type Date
  430.     *   )
  431.     * )
  432.     * </pre>
  433.     *
  434.     * @access   public
  435.     * @param    mixed   $date       date (timestamp | string | PEAR::Date object)
  436.     * @param    string  $locale     locale setting that shall be used by this method
  437.     * @param    boolean $multiple 
  438.     * @return   object  object of type Date_Holidays_Holiday on success
  439.     *                    (numeric array of those on multiple search),
  440.     *                    if no holiday was found, matching this date, null is returned
  441.     * @throws   object PEAR_Error   DATE_HOLIDAYS_INVALID_DATE, DATE_HOLIDAYS_INVALID_DATE_FORMAT
  442.     * @uses     getHoliday()
  443.     * @uses     getHolidayTitle()
  444.     * @see      getHoliday()
  445.     ***/
  446.     function getHolidayForDate($date$locale = null$multiple = false)
  447.     {
  448.         if (!is_a($date'Date')) {
  449.             $date &$this->_convertDate($date);
  450.             if (Date_Holidays::isError($date)) {
  451.                 return $date;
  452.             }
  453.         }
  454.         $isodate $date->format('%Y-%m-%d');
  455.         unset($date);
  456.         if (is_null($locale)) {
  457.             $locale $this->_locale;
  458.         }
  459.         if (array_key_exists($isodate$this->_holidays)) {
  460.             if (!$multiple{
  461.                 //get only the first feast for this day
  462.                 $internalName $this->_holidays[$isodate][0];
  463.                 $result &$this->getHoliday($internalName$locale);
  464.                 return Date_Holidays::isError($result? null : $result;
  465.             }
  466.             // array that collects data, if multiple searching is done
  467.             $data = array();
  468.             foreach($this->_holidays[$isodateas $internalName{
  469.                 $result &$this->getHoliday($internalName$locale);
  470.                 if (Date_Holidays::isError($result)) {
  471.                     continue;
  472.                 }
  473.                 $data[=$result;
  474.             }
  475.             return $data;
  476.         }
  477.         return null;
  478.     }
  479.     
  480.    /**
  481.     * Converts timestamp or date-string into da PEAR::Date object
  482.     *
  483.     * @static
  484.     * @access   private
  485.     * @param    mixed   $date   date
  486.     * @return   object PEAR_Date 
  487.     * @throws   object PEAR_Error   DATE_HOLIDAYS_INVALID_DATE, DATE_HOLIDAYS_INVALID_DATE_FORMAT
  488.     */
  489.     function _convertDate($date)
  490.     {
  491.         if (is_string($date)) {
  492.             if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}/'$date)) {
  493.                 return Date_Holidays::raiseError(DATE_HOLIDAYS_INVALID_DATE_FORMAT
  494.                     'Date-string has wrong format (must be YYYY-MM-DD)');
  495.             }
  496.             return new Date($date);
  497.         }
  498.         
  499.         if (is_int($date)) {
  500.             return new Date($date);
  501.         }
  502.         
  503.             'The date you specified is invalid');
  504.     }
  505.     
  506.    /**
  507.     * Adds all holidays in the array to the driver's internal list of holidays.
  508.     * 
  509.     * Format of the array:
  510.     * <pre>
  511.     *   array(
  512.     *       'newYearsDay'   => array(
  513.     *           'date'          => '01-01',
  514.     *           'title'         => 'New Year\'s Day',
  515.     *           'translations'  => array(
  516.     *               'de_DE' =>  'Neujahr',
  517.     *               'en_EN' =>  'New Year\'s Day'
  518.     *           )
  519.     *       ),
  520.     *       'valentinesDay' => array(
  521.     *           ...
  522.     *       )
  523.     *   );
  524.     * </pre>
  525.     * 
  526.     * @access   protected
  527.     * @param    array       $holidays   static holidays' data
  528.     * @uses     _addHoliday()
  529.     */
  530.     function _addStaticHolidays($holidays)
  531.     {
  532.         foreach ($holidays as $internalName => $holiday{
  533.             // add the holiday's basic data
  534.             $this->_addHoliday($internalName$this->_year . '-' $holiday['date']$holiday['title']);
  535.         }
  536.     }
  537.     
  538.    /**
  539.     * Adds a holiday to the driver's holidays
  540.     *
  541.     * @access   protected
  542.     * @param    string  $internalName   internal name - must not contain characters that aren't allowed as variable-names
  543.     * @param    mixed   $date           date (timestamp | string | PEAR::Date object)
  544.     * @param    string  $title          holiday title
  545.     */
  546.     function _addHoliday($internalName$date$title)
  547.     {
  548.         if (is_a($date'Date')) {
  549.             $date   =&  new Date($date);
  550.         }
  551.         
  552.         $this->_dates[$internalName]        &$date;
  553.         $this->_titles['C'][$internalName]  $title;
  554.         $isodate $date->format('%Y-%m-%d');
  555.         if (!isset($this->_holidays[$isodate])) {
  556.             $this->_holidays[$isodate= array();
  557.         }
  558.         array_push($this->_holidays[$isodate]$internalName);
  559.         array_push($this->_internalNames$internalName);
  560.     }
  561.     
  562.    /**
  563.     * Add a localized translation for a holiday's title
  564.     *
  565.     * @access   protected
  566.     * @param    string  $internalName   internal name of an existing holiday
  567.     * @param    string  $locale         locale setting that shall be used by this method
  568.     * @param    string  $title          title
  569.     * @return   true on success, otherwise a PEAR_Error object
  570.     * @throws   object PEAR_Error       DATE_HOLIDAYS_INVALID_INTERNAL_NAME
  571.     */
  572.     function _addTranslationForHoliday($internalName$locale$title)
  573.     {
  574.         if (in_array($internalName$this->_internalNames)) {
  575.                 'Couldn\'t add translation (' $locale ') for holiday with this internal name: ' $internalName);
  576.         }
  577.         
  578.         if (in_array($locale$this->_availableLocales)) {
  579.             array_push($this->_availableLocales$locale);
  580.         }
  581.         $this->_titles[$locale][$internalName]  $title;
  582.         return true;
  583.     }
  584.     
  585.    /**
  586.     * Add a translation-file's content
  587.     * 
  588.     * The translation-file's content will be parsed and translations for
  589.     * holidays will be made available with the specified locale.
  590.     * 
  591.     * @access   public
  592.     * @param    string  $file   filename of the language file
  593.     * @param    string  $locale locale-code of the translation
  594.     * @return   boolean true on success, otherwise a PEAR_ErrorStack object
  595.     * @throws   object PEAR_Errorstack
  596.     */
  597.     function addTranslationFile($file$locale)
  598.     {
  599.         if (file_exists($file)) {
  600.             Date_Holidays::raiseError(DATE_HOLIDAYS_LANGUAGEFILE_NOT_FOUND'Language-file not found');
  601.             return Date_Holidays::getErrorStack();
  602.         }
  603.         
  604.         $content    parse_ini_file($file);
  605.         foreach ($content as $internalName => $translation{
  606.             $this->_addTranslationForHoliday($internalName$locale$translation);
  607.         }
  608.         
  609.         if (Date_Holidays::errorsOccurred()) {
  610.             return Date_Holidays::getErrorStack();
  611.         }
  612.         return true;
  613.     }
  614.     
  615.    /**
  616.     * Remove a holiday from internal storage
  617.     *
  618.     * This method should be used within driver classes to unset holidays that were inherited from
  619.     * parent-drivers
  620.     *
  621.     * @access   protected
  622.     * @param    $string     $internalName   internal name
  623.     * @return   boolean     true on success, otherwise a PEAR_Error object
  624.     * @throws   object PEAR_Error   DATE_HOLIDAYS_INVALID_INTERNAL_NAME
  625.     */
  626.     function _removeHoliday($internalName)
  627.     {
  628.         if (in_array($internalName$this->_internalNames)) {
  629.                 'Couldn\'t remove holiday with this internal name: ' $internalName);
  630.         }
  631.         
  632.         if (isset($this->_dates[$internalName])) {
  633.             unset($this->_dates[$internalName]);
  634.         }
  635.         $locales    array_keys($this->_titles);
  636.         foreach ($locales as $locale{
  637.             if (isset($this->_titles[$locale][$internalName])) {
  638.                 unset($this->_titles[$locale][$internalName]);
  639.             }
  640.         }
  641.         $index      array_search($internalName$this->_internalNames);
  642.         if (is_null($index)) {
  643.             unset($this->_internalNames[$index]);
  644.         }
  645.         return true;
  646.     }
  647.     
  648.    /**
  649.     * Finds the best internally available locale for the specified one
  650.     *
  651.     * @access   protected
  652.     * @param    string  $locale locale
  653.     * @return   string  best locale available
  654.     */
  655.     function _findBestLocale($locale)
  656.     {
  657.         /* exact locale is available */
  658.         if (in_array($locale$this->_availableLocales)) {
  659.             return $locale;
  660.         }
  661.         
  662.         /* first two letter are equal */
  663.         foreach ($this->_availableLocales as $aLocale{
  664.             if (strncasecmp($aLocale$locale2== 0{
  665.                 return $aLocale;
  666.             }
  667.         }
  668.         
  669.         /* no appropriate locale available, will use driver's internal locale */
  670.         return 'C';
  671.     }
  672.     
  673.    /**
  674.     * Returns date of a holiday
  675.     *
  676.     * @access   public
  677.     * @param    string  $internalName   internal name for holiday
  678.     * @return   object Date             date of the holiday as PEAR::Date object on success, otherwise a PEAR_Error object
  679.     * @throws   object PEAR_Error       DATE_HOLIDAYS_INVALID_INTERNAL_NAME, DATE_HOLIDAYS_DATE_UNAVAILABLE
  680.     */
  681.     function getHolidayDate($internalName)
  682.     {
  683.         if (in_array($internalName$this->_internalNames)) {
  684.             return Date_Holidays::raiseError(DATE_HOLIDAYS_INVALID_INTERNAL_NAME'Invalid internal name: ' $internalName);
  685.         }
  686.         
  687.         if (isset($this->_dates[$internalName])) {
  688.             return Date_Holidays::raiseError(DATE_HOLIDAYS_DATE_UNAVAILABLE'Date for holiday with internal name ' $internalName 
  689.                 ' is not available');
  690.         }
  691.         
  692.         return $this->_dates[$internalName];
  693.     }
  694.     
  695.    /**
  696.     * Returns dates of all holidays or those accepted by the applied filter.
  697.     *
  698.     * Structure of the returned array:
  699.     * <pre>
  700.     * array(
  701.     *   'internalNameFoo' => object of type date,
  702.     *   'internalNameBar' => object of type date
  703.     * )
  704.     * </pre>
  705.     *
  706.     * @access   public
  707.     * @param    Date_Holidays_Filter    filter-object (or an array !DEPRECATED!)
  708.     * @return   array with holidays' dates on success, otherwise a PEAR_Error object
  709.     * @throws   object PEAR_Error   DATE_HOLIDAYS_INVALID_INTERNAL_NAME
  710.     * @uses     getHolidayDate()
  711.     */
  712.     function getHolidayDates($filter = null)
  713.     {
  714.         if (is_null($filter)) {
  715.             $filter &new Date_Holidays_Filter_Blacklist(array());
  716.         elseif (is_array($filter)) {
  717.             $filter &new Date_Holidays_Filter_Whitelist($filter);
  718.         }
  719.         
  720.         $dates = array();
  721.         
  722.         foreach ($this->_internalNames as $internalName{
  723.             if ($filter->accept($internalName)) {
  724.                 $date &$this->getHolidayDate($internalName);
  725.                 if (Date_Holidays::isError($date)) {
  726.                     return $date;
  727.                 }
  728.                 $dates[$internalName&$this->getHolidayDate($internalName);
  729.             }
  730.         }
  731.         return $dates;
  732.     }
  733.     
  734.    /**
  735.     * Sets the driver's locale
  736.     *
  737.     * @access   public
  738.     * @param    string  $locale locale
  739.     */
  740.     function setLocale($locale)
  741.     {
  742.         $this->_locale  =   $locale;
  743.     }
  744. }
  745. ?>

Documentation generated on Mon, 11 Mar 2019 14:23:52 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.