home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Calendar / Factory.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  5.8 KB  |  145 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. //
  4. // +----------------------------------------------------------------------+
  5. // | PHP Version 4                                                        |
  6. // +----------------------------------------------------------------------+
  7. // | Copyright (c) 1997-2002 The PHP Group                                |
  8. // +----------------------------------------------------------------------+
  9. // | This source file is subject to version 2.02 of the PHP license,      |
  10. // | that is bundled with this package in the file LICENSE, and is        |
  11. // | available at through the world-wide-web at                           |
  12. // | http://www.php.net/license/3_0.txt.                                  |
  13. // | If you did not receive a copy of the PHP license and are unable to   |
  14. // | obtain it through the world-wide-web, please send a note to          |
  15. // | license@php.net so we can mail you a copy immediately.               |
  16. // +----------------------------------------------------------------------+
  17. // | Authors: Harry Fuecks <hfuecks@phppatterns.com>                      |
  18. // |          Lorenzo Alberton <l dot alberton at quipo dot it>           |
  19. // +----------------------------------------------------------------------+
  20. //
  21. // $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $
  22. //
  23. /**
  24.  * @package Calendar
  25.  * @version $Id: Factory.php,v 1.3 2005/10/22 10:08:47 quipo Exp $
  26.  */
  27.  
  28. /**
  29.  * Allows Calendar include path to be redefined
  30.  * @ignore
  31.  */
  32. if (!defined('CALENDAR_ROOT')) {
  33.     define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
  34. }
  35.  
  36. /**
  37.  * Load Calendar base class
  38.  */
  39. require_once CALENDAR_ROOT.'Calendar.php';
  40.  
  41. /**
  42.  * Contains a factory method to return a Singleton instance of a class
  43.  * implementing the Calendar_Engine_Interface.<br>
  44.  * For Month objects, to control type of month returned, use CALENDAR_MONTH_STATE
  45.  * constact e.g.;
  46.  * <code>
  47.  * require_once 'Calendar/Factory.php';
  48.  * define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKDAYS); // Use Calendar_Month_Weekdays
  49.  * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH_WEEKS); // Use Calendar_Month_Weeks
  50.  * // define ('CALENDAR_MONTH_STATE',CALENDAR_USE_MONTH); // Use Calendar_Month
  51.  * </code>
  52.  * It defaults to building Calendar_Month objects.<br>
  53.  * Use the constract CALENDAR_FIRST_DAY_OF_WEEK to control the first day of the week
  54.  * for Month or Week objects (e.g. 0 = Sunday, 6 = Saturday)
  55.  * @package Calendar
  56.  * @access protected
  57.  */
  58. class Calendar_Factory
  59. {
  60.     /**
  61.      * Creates a calendar object given the type and units
  62.      * @param string class of calendar object to create
  63.      * @param int year
  64.      * @param int month
  65.      * @param int day
  66.      * @param int hour
  67.      * @param int minute
  68.      * @param int second
  69.      * @return object subclass of Calendar
  70.      * @access public
  71.      * @static
  72.      */
  73.     function create($type, $y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0)
  74.     {
  75.         $firstDay = defined('CALENDAR_FIRST_DAY_OF_WEEK') ? CALENDAR_FIRST_DAY_OF_WEEK : 1;
  76.         switch ($type) {
  77.             case 'Day':
  78.                 require_once CALENDAR_ROOT.'Day.php';
  79.                 return new Calendar_Day($y,$m,$d);
  80.             case 'Month':
  81.                 // Set default state for which month type to build
  82.                 if (!defined('CALENDAR_MONTH_STATE')) {
  83.                     define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH);
  84.                 }
  85.                 switch (CALENDAR_MONTH_STATE) {
  86.                     case CALENDAR_USE_MONTH_WEEKDAYS:
  87.                         require_once CALENDAR_ROOT.'Month/Weekdays.php';
  88.                         $class = 'Calendar_Month_Weekdays';
  89.                         break;
  90.                     case CALENDAR_USE_MONTH_WEEKS:
  91.                         require_once CALENDAR_ROOT.'Month/Weeks.php';
  92.                         $class = 'Calendar_Month_Weeks';
  93.                         break;
  94.                     case CALENDAR_USE_MONTH:
  95.                     default:
  96.                         require_once CALENDAR_ROOT.'Month.php';
  97.                         $class = 'Calendar_Month';
  98.                         break;
  99.                 }
  100.                 return new $class($y, $m, $firstDay);
  101.             case 'Week':
  102.                 require_once CALENDAR_ROOT.'Week.php';
  103.                 return new Calendar_Week($y, $m, $d, $firstDay);
  104.             case 'Hour':
  105.                 require_once CALENDAR_ROOT.'Hour.php';
  106.                 return new Calendar_Hour($y, $m, $d, $h);
  107.             case 'Minute':
  108.                 require_once CALENDAR_ROOT.'Minute.php';
  109.                 return new Calendar_Minute($y, $m, $d, $h, $i);
  110.             case 'Second':
  111.                 require_once CALENDAR_ROOT.'Second.php';
  112.                 return new Calendar_Second($y,$m,$d,$h,$i,$s);
  113.             case 'Year':
  114.                 require_once CALENDAR_ROOT.'Year.php';
  115.                 return new Calendar_Year($y);
  116.             default:
  117.                 require_once 'PEAR.php';
  118.                 PEAR::raiseError(
  119.                     'Calendar_Factory::create() unrecognised type: '.$type, null, PEAR_ERROR_TRIGGER,
  120.                     E_USER_NOTICE, 'Calendar_Factory::create()');
  121.                 return false;
  122.         }
  123.     }
  124.     /**
  125.      * Creates an instance of a calendar object, given a type and timestamp
  126.      * @param string type of object to create
  127.      * @param mixed timestamp (depending on Calendar engine being used)
  128.      * @return object subclass of Calendar
  129.      * @access public
  130.      * @static
  131.      */
  132.     function & createByTimestamp($type, $stamp)
  133.     {
  134.         $cE = & Calendar_Engine_Factory::getEngine();
  135.         $y = $cE->stampToYear($stamp);
  136.         $m = $cE->stampToMonth($stamp);
  137.         $d = $cE->stampToDay($stamp);
  138.         $h = $cE->stampToHour($stamp);
  139.         $i = $cE->stampToMinute($stamp);
  140.         $s = $cE->stampToSecond($stamp);
  141.         $cal = Calendar_Factory::create($type, $y, $m, $d, $h, $i, $s);
  142.         return $cal;
  143.     }
  144. }
  145. ?>