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

Source for file Holidays.php

Documentation is available at Holidays.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: Holidays.php,v 1.19 2004/08/09 18:03:49 luckec Exp $
  20.  
  21. /**
  22.  * uses PEAR errors
  23.  */
  24. require_once 'PEAR.php';
  25.  
  26. /**
  27.  * uses PEAR::Date
  28.  */
  29. require_once 'Date.php';
  30.  
  31. /**
  32.  * Class that wraps a holidays data
  33.  */
  34. require_once 'Date/Holidays/Holiday.php';
  35.     
  36. /**
  37.  * could not find file of driver-class
  38.  *
  39.  * @access  public
  40.  */
  41. define('DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND'1);
  42.  
  43. /**
  44.  * class that helps you to locate holidays for a year
  45.  *
  46.  * @abstract
  47.  * @category Date
  48.  * @package  Date_Holidays
  49.  * @version  $Id: Holidays.php,v 1.19 2004/08/09 18:03:49 luckec Exp $
  50.  * @author   Carsten Lucke <luckec@tool-garage.de>
  51.  * @author   Stephan Schmidt <schst@php.net>
  52.  */
  53. class Date_Holidays 
  54. {
  55.   /**
  56.     * Constructor
  57.     *
  58.     * Use the Date_Holidays::factory() method to construct an object of a certain driver
  59.     *
  60.     * @access   protected
  61.     */
  62.     function Date_Holidays()
  63.     {
  64.     }
  65.     
  66.    /**
  67.     * Factory method that creates a driver-object
  68.     *
  69.     * @static
  70.     * @access   public
  71.     * @param    string  $driverId   driver-name
  72.     * @return   object  Date_Holidays driver-object on success, otherwise a PEAR_Error object
  73.     * @throws   object PEAR_Error
  74.     */
  75.     function factory($driverId$year = null$locale = null)
  76.     {
  77.         if (isset($GLOBALS['_DATE_HOLIDAYS']['DIE_ON_MISSING_LOCALE'])) {
  78.             Date_Holidays::staticSetProperty('DIE_ON_MISSING_LOCALE'true);
  79.         }
  80.         
  81.         $driverClass        =   'Date_Holidays_Driver_' $driverId;
  82.         if (class_exists($driverClass)) {
  83.             $driverFile     =   'Date' . DIRECTORY_SEPARATOR . 'Holidays' . DIRECTORY_SEPARATOR . 
  84.                 'Driver' . DIRECTORY_SEPARATOR . $driverId '.php';
  85.  
  86.             require_once 'Date/Holidays/Driver.php';
  87.             @include_once $driverFile;
  88.             if (class_exists($driverClass)) {
  89.                 return Date_Holidays::raiseError(DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND
  90.                     'Couldn\'t find file of the driver-class,  filename: ' $driverFile);
  91.             }
  92.         }
  93.         $driver             =&  new $driverClass;
  94.         
  95.         if (is_null($year)) {
  96.             $year           =   date('Y');
  97.         }
  98.         // sets internal var $_year and performs _buildHolidays()
  99.         $res                =   $driver->setYear($year);
  100.         if (Date_Holidays::isError($res)) {
  101.             return $res;
  102.         }
  103.  
  104.         if (is_null($locale)) {
  105.             $locale         =   setlocale(LC_ALLnull);
  106.         }
  107.         $driver->setLocale($locale);
  108.         return $driver;
  109.     }
  110.     
  111.    /**
  112.     * Returns the error-stack
  113.     *
  114.     * @static
  115.     * @access   public
  116.     * @return   object PEAR_ErrorStack  error-stack
  117.     */
  118.     function &getErrorStack()
  119.     {
  120.         return PEAR_ErrorStack::singleton('Date_Holidays'falsefalsetrue);
  121.     }
  122.     
  123.    /**
  124.     * Pushes a new error on the error-stack and returns a PEAR_Error object
  125.     *
  126.     * @static
  127.     * @access   public
  128.     * @param    int     $code   error-code
  129.     * @param    string  $msg    error-message
  130.     * @return   object PEAR_Error 
  131.     */
  132.     function raiseError($code$msg = null)
  133.     {
  134.         $errorStack &Date_Holidays::getErrorStack();
  135.         return $errorStack->push($code'error'array()$msgfalsedebug_backtrace());
  136.     }
  137.     
  138.    /**
  139.     * Checks a variable to determine whether it represnts an error object or not
  140.     *
  141.     * @static
  142.     * @access   public
  143.     * @param    mixed   $data   variable to test
  144.     * @param    int     $code   if $data is an PEAR_Error object, return true
  145.     *                            only if $code is a string and
  146.     *                            $obj->getMessage() == $code or
  147.     *                            $code is an integer and $obj->getCode() == $code
  148.     * @return   boolean true if $subject is an error object
  149.     */
  150.     function isError($data$code = null)
  151.     {
  152.         $errorClass get_class($data);
  153.         switch (strtolower($errorClass)) {
  154.             case 'pear_error':
  155.                 return PEAR::isError($data$code);
  156.                 break;
  157.             case 'pear_errorstack':
  158.                 return $data->hasErrors();
  159.                 break;
  160.         }
  161.         return false;
  162.     }
  163.     
  164.    /**
  165.     * Checks whether errors occured
  166.     *
  167.     * @static
  168.     * @access   public
  169.     * @return   boolean true if errors occurred
  170.     */
  171.     function errorsOccurred()
  172.     {
  173.         $errorStack &Date_Holidays::getErrorStack();
  174.         return $errorStack->hasErrors();
  175.     }
  176.     
  177.    /**
  178.     * Returns the errors the error-stack contains
  179.     * 
  180.     * @static
  181.     * @access   public
  182.     * @param    boolean $purge  true if the stall shall be purged
  183.     * @return   array   errors
  184.     */
  185.     function getErrors($purge = false)
  186.     {
  187.         $errorStack &Date_Holidays::getErrorStack();
  188.         return $errorStack->getErrors($purge);
  189.     }
  190.     
  191.    /**
  192.     * Set a property for the Date_Holidays drivers
  193.     *
  194.     * Available properties:
  195.     * <pre>
  196.     * DIE_ON_MISSING_LOCALE = boolean
  197.     *   false: if no localized holiday-title is found an error will be returned
  198.     *   true: if no localized holiday-title is found the internal translation (English) will be used
  199.     * </pre>
  200.     * 
  201.     * @static
  202.     * @access   public
  203.     * @param    string  $prop   property
  204.     * @param    string  $value  property-value
  205.     */
  206.     function staticSetProperty($prop$value)
  207.     {
  208.         if (isset($GLOBALS['_DATE_HOLIDAYS'])) {
  209.             $GLOBALS['_DATE_HOLIDAYS'= array();
  210.         }
  211.         
  212.         switch ($prop{
  213.             case 'DIE_ON_MISSING_LOCALE':
  214.                 if (is_bool($value)) {
  215.                     $GLOBALS['_DATE_HOLIDAYS'][$prop$value;
  216.                 }
  217.                 break;
  218.                 
  219.             default:
  220.                 break;
  221.         }
  222.     }
  223.     
  224.    /**
  225.     * Returns an internal property value
  226.     *
  227.     * @static
  228.     * @access   public
  229.     * @param    string  $prop   property-name
  230.     * @return   mixed   property value on success, otherwise null
  231.     */
  232.     function staticGetProperty($prop)
  233.     {
  234.         if (isset($GLOBALS['_DATE_HOLIDAYS'])) {
  235.             return null;
  236.         }
  237.         
  238.         switch ($prop{
  239.             case 'DIE_ON_MISSING_LOCALE':
  240.                 if (isset($GLOBALS['_DATE_HOLIDAYS'][$prop])) {
  241.                     return $GLOBALS['_DATE_HOLIDAYS'][$prop];
  242.                 }
  243.                 return null;
  244.                 break;
  245.                 
  246.             default:
  247.                 return null;
  248.                 break;
  249.         }
  250.     }
  251. }
  252. ?>

Documentation generated on Mon, 11 Mar 2019 13:54:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.