1<?php 2/** 3 * Example how to create an own driver-class for Date_Holidays 4 * 5 * To test this class, you have to copy it into the drivers-directory. 6 * 7 * The classname has to be something like Date_Holidays_Driver_*. 8 * Otherwise it won't be compatible to be used within PEAR's strict directory 9 * structure. 10 * 11 * PHP Version 5 12 * 13 * @category Date 14 * @package Date_Holidays 15 * @author Carsten Lucke <luckec@tool-garage.de> 16 * @license http://www.php.net/license/3_01.txt PHP License 3.0.1 17 * @link http://pear.php.net/package/Date_Holidays 18 */ 19class Date_Holidays_Driver_Example extends Date_Holidays_Driver 20{ 21 /** 22 * Constructor 23 * 24 * Use the Date_Holidays::factory() method to construct an object of a 25 * certain driver 26 * 27 * @access protected 28 */ 29 function Date_Holidays_Driver_Example() 30 { 31 } 32 33 /** 34 * Build the internal arrays that contain data about the calculated holidays 35 * 36 * @access protected 37 * @return boolean true on success, otherwise a PEAR_ErrorStack object 38 * @throws object PEAR_ErrorStack 39 */ 40 function _buildHolidays() 41 { 42 /** 43 * If your driver is extending another driver-class and is not a direct 44 * descendant of the Date_Holidays_Driver base-class you will want to 45 * build this classes' holidays before you start with your turn. 46 * 47 * So just call the _buildHolidays() method of that class. 48 */ 49 parent::_buildHolidays(); 50 51 /** 52 * There are two methods to add a holiday. One for adding holidays in 53 * general and on that can be used to add static holidays (every year 54 * the same day). 55 * 56 * You always have to give the added holiday an unique internal name 57 * within your driver. 58 * This should describe the holiday as good as possible. 59 * 60 * Of course you need a date and a title (the default title should 61 * always be in English) 62 * 63 * You can add as many translations as you want for your driver's 64 * holidays. 65 * Although the default title is in English you should add another one 66 * with the correct locale setting. 67 */ 68 69 /* 70 * General method to add a holiday 71 */ 72 73 // a static holiday 74 $this->_addHoliday('jesusCircumcision', 75 $this->_year . '-01-01', 76 'Circumcision of Jesus'); 77 78 // a calculated holiday 79 // if you are using helper methods to calculate movable holidays is 80 // your own decision 81 $fooDate = $this->_calcFirstMondayInJanuary(); 82 $this->_addHoliday('firstMondayInJan', 83 $fooDate, 84 'First monday in January'); 85 86 /* 87 * Special method for adding static holidays: 88 */ 89 $static = array('newYearsDay' => array('date' => '01-01', 90 'title' => 'New Year\'s Day'), 91 'valentinesDay' => array('date' => '02-14', 92 'title' => 'Valentine\'s Day')); 93 $this->_addStaticHolidays($static); 94 if (Date_Holidays::errorsOccurred()) { 95 return Date_Holidays::getErrorStack(); 96 } 97 return true; 98 } 99 100 /** 101 * A helper method 102 * 103 * @access private 104 * @return object Date date of first monday in actual years january 105 */ 106 function _calcFirstMondayInJanuary() 107 { 108 $date = new Date($this->_year . '-01-01'); 109 while ($date->getDayOfWeek() != 1) { 110 $date = $date->getNextDay(); 111 } 112 return $date; 113 } 114} 115?> 116