cvs: pear /Date_Holidays Holidays.php /Date_Holidays/Holidays Driver.php Holiday.php /Date_Holidays/lang/Christian de_DE.xml en_EN.xml

From: Date: Mon, 01 Aug 2005 20:11:21 +0000
Subject: cvs: pear /Date_Holidays Holidays.php /Date_Holidays/Holidays Driver.php Holiday.php /Date_Holidays/lang/Christian de_DE.xml en_EN.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-33516@lists.php.net to get a copy of this message
luckec Mon Aug 1 16:11:21 2005 EDT Modified files: /pear/Date_Holidays Holidays.php /pear/Date_Holidays/Holidays Driver.php Holiday.php /pear/Date_Holidays/lang/Christian de_DE.xml en_EN.xml Log: implemented properties-feature, every holiday can have an unlimited number of properties for additional information (i18n-aware), language-file are xml-based now

http://cvs.php.net/diff.php/pear/Date_Holidays/Holidays.php?r1=1.4&r2=1.5&ty=u Index: pear/Date_Holidays/Holidays.php diff -u pear/Date_Holidays/Holidays.php:1.4 pear/Date_Holidays/Holidays.php:1.5 --- pear/Date_Holidays/Holidays.php:1.4 Thu May 19 16:39:51 2005 +++ pear/Date_Holidays/Holidays.php Mon Aug 1 16:11:18 2005 @@ -16,7 +16,7 @@ // | Authors: Carsten Lucke <luckec@tool-garage.de> | // +----------------------------------------------------------------------+ // -// $Id: Holidays.php,v 1.4 2005/05/19 20:39:51 luckec Exp $ +// $Id: Holidays.php,v 1.5 2005/08/01 20:11:18 luckec Exp $ /** * uses PEAR errors @@ -44,6 +44,13 @@ * @access public */ define('DATE_HOLIDAYS_ERROR_DRIVERFILE_NOT_FOUND', 1); + +/** + * invalid argument was passed to a method + * + * @access public + */ +define('DATE_HOLIDAYS_ERROR_INVALID_ARGUMENT', 2); /** * class that helps you to locate holidays for a year @@ -51,7 +58,7 @@ * @abstract * @category Date * @package Date_Holidays - * @version $Id: Holidays.php,v 1.4 2005/05/19 20:39:51 luckec Exp $ + * @version $Id: Holidays.php,v 1.5 2005/08/01 20:11:18 luckec Exp $ * @author Carsten Lucke <luckec@tool-garage.de> * @author Stephan Schmidt <schst@php.net> */ http://cvs.php.net/diff.php/pear/Date_Holidays/Holidays/Driver.php?r1=1.11&r2=1.12&ty=u Index: pear/Date_Holidays/Holidays/Driver.php diff -u pear/Date_Holidays/Holidays/Driver.php:1.11 pear/Date_Holidays/Holidays/Driver.php:1.12 --- pear/Date_Holidays/Holidays/Driver.php:1.11 Sun Jul 31 14:10:30 2005 +++ pear/Date_Holidays/Holidays/Driver.php Mon Aug 1 16:11:21 2005 @@ -16,7 +16,7 @@ // | Authors: Carsten Lucke <luckec@tool-garage.de> | // +----------------------------------------------------------------------+ // -// $Id: Driver.php,v 1.11 2005/07/31 18:10:30 luckec Exp $s +// $Id: Driver.php,v 1.12 2005/08/01 20:11:21 luckec Exp $s /** * uses PEAR_Errorstack @@ -81,7 +81,7 @@ * @category Date * @package Date_Holidays * @subpackage Driver - * @version $Id: Driver.php,v 1.11 2005/07/31 18:10:30 luckec Exp $ + * @version $Id: Driver.php,v 1.12 2005/08/01 20:11:21 luckec Exp $ * @author Carsten Lucke <luckec@tool-garage.de> */ class Date_Holidays_Driver @@ -315,6 +315,38 @@ $this->_titles[$locale][$internalName] : $this->_titles['C'][$internalName]; } + + /** + * Returns the localized properties of a holiday. If no properties have been stored an empty + * array will be returned. + * + * @access public + * @param string $internalName internal name for holiday + * @param string $locale locale setting that shall be used by this method + * @return array array of properties on success, otherwise a PEAR_Error object + * @throws object PEAR_Error DATE_HOLIDAYS_INVALID_INTERNAL_NAME + */ + function getHolidayProperties($internalName, $locale = null) + { + if (! in_array($internalName, $this->_internalNames)) { + return Date_Holidays::raiseError(DATE_HOLIDAYS_INVALID_INTERNAL_NAME, 'Invalid internal name: ' . $internalName); + } + + if (is_null($locale)) { + $locale = $this->_findBestLocale($this->_locale); + } else { + $locale = $this->_findBestLocale($locale); + } + + + $properties = array(); + if (isset($this->_holidayProperties[$internalName][$locale])) { + $properties = $this->_holidayProperties[$internalName][$locale]; + } + return $properties; + } + + /** * Returns all holidays that the driver knows. * @@ -349,10 +381,7 @@ foreach ($this->_internalNames as $internalName) { if ($filter->accept($internalName)) { - if (! in_array($internalName, $this->_internalNames)) { - return Date_Holidays::raiseError(DATE_HOLIDAYS_INVALID_INTERNAL_NAME, - 'Invalid internal name: ' . $internalName); - } + // no need to check for valid internal-name, will be done by #getHoliday() $holidays[$internalName] = &$this->getHoliday($internalName); } } @@ -397,10 +426,9 @@ if (Date_Holidays::isError($date)) { return $date; } - - $properties = null; - if (isset($this->_holidayProperties[$internalName][$locale])) { - $properties = $this->_holidayProperties[$internalName][$locale]; + $properties = &$this->getHolidayProperties($internalName, $locale); + if (Date_Holidays::isError($properties)) { + return $properties; } return new Date_Holidays_Holiday($internalName, $title, $date, $properties); @@ -710,36 +738,6 @@ } /** - * Add a translation-file's content - * - * The translation-file's content will be parsed and translations for - * holidays will be made available with the specified locale. - * - * @access public - * @param string $file filename of the language file - * @param string $locale locale-code of the translation - * @return boolean true on success, otherwise a PEAR_ErrorStack object - * @throws object PEAR_Errorstack - */ - function addTranslationFile($file, $locale) - { - if (! file_exists($file)) { - Date_Holidays::raiseError(DATE_HOLIDAYS_LANGUAGEFILE_NOT_FOUND, 'Language-file not found'); - return Date_Holidays::getErrorStack(); - } - - $content = parse_ini_file($file); - foreach ($content as $internalName => $translation) { - $this->_addTranslationForHoliday($internalName, $locale, $translation); - } - - if (Date_Holidays::errorsOccurred()) { - return Date_Holidays::getErrorStack(); - } - return true; - } - - /** * Add a language-file's content * * The language-file's content will be parsed and translations, properties, etc. for @@ -750,9 +748,9 @@ * @param string $locale locale-code of the translation * @return boolean true on success, otherwise a PEAR_ErrorStack object * @throws object PEAR_Errorstack - * @todo Could also accept a Unserializer object as parameter + * @todo Could also accept an Unserializer object as parameter */ - function addLanguageFile($file, $locale) + function addTranslationFile($file, $locale) { if (! file_exists($file)) { Date_Holidays::raiseError(DATE_HOLIDAYS_LANGUAGEFILE_NOT_FOUND, 'Language-file not found'); @@ -779,9 +777,11 @@ $this->_addTranslationForHoliday($holiday['internal-name'], $locale, $holiday['translation']); - foreach ($holiday['properties'] as $propId => $propVal) { - $this->_addStringPropertyForHoliday($holiday['internal-name'], $locale, - $propId, $propVal); + if (isset($holiday['properties']) && is_array($holiday['properties'])) { + foreach ($holiday['properties'] as $propId => $propVal) { + $this->_addStringPropertyForHoliday($holiday['internal-name'], $locale, + $propId, $propVal); + } } } http://cvs.php.net/diff.php/pear/Date_Holidays/Holidays/Holiday.php?r1=1.2&r2=1.3&ty=u Index: pear/Date_Holidays/Holidays/Holiday.php diff -u pear/Date_Holidays/Holidays/Holiday.php:1.2 pear/Date_Holidays/Holidays/Holiday.php:1.3 --- pear/Date_Holidays/Holidays/Holiday.php:1.2 Thu May 19 16:42:55 2005 +++ pear/Date_Holidays/Holidays/Holiday.php Mon Aug 1 16:11:21 2005 @@ -16,14 +16,14 @@ // | Authors: Carsten Lucke <luckec@tool-garage.de> | // +----------------------------------------------------------------------+ // -// $Id: Holiday.php,v 1.2 2005/05/19 20:42:55 luckec Exp $ +// $Id: Holiday.php,v 1.3 2005/08/01 20:11:21 luckec Exp $ /** * Simple class that wraps a holiday's data * * @category Date * @package Date_Holidays - * @version $Id: Holiday.php,v 1.2 2005/05/19 20:42:55 luckec Exp $ + * @version $Id: Holiday.php,v 1.3 2005/08/01 20:11:21 luckec Exp $ * @author Carsten Lucke <luckec@tool-garage.de> */ class Date_Holidays_Holiday @@ -58,7 +58,7 @@ * @access private * @var array */ - var $_properties = array(); + var $_properties; /** * Constructor @@ -73,8 +73,16 @@ { $this->_internalName = $internalName; $this->_title = $title; - $this->_date = &$date; - $this->_properties = $properties; + $this->_date = null; + $this->_properties = array(); + + if (is_a($date, 'Date')) { + $this->_date = &$date; + } + + if (is_array($properties)) { + $this->_properties = $properties; + } } /** http://cvs.php.net/diff.php/pear/Date_Holidays/lang/Christian/de_DE.xml?r1=1.1&r2=1.2&ty=u Index: pear/Date_Holidays/lang/Christian/de_DE.xml diff -u pear/Date_Holidays/lang/Christian/de_DE.xml:1.1 pear/Date_Holidays/lang/Christian/de_DE.xml:1.2 --- pear/Date_Holidays/lang/Christian/de_DE.xml:1.1 Thu May 19 16:35:45 2005 +++ pear/Date_Holidays/lang/Christian/de_DE.xml Mon Aug 1 16:11:21 2005 @@ -6,6 +6,9 @@ <holiday> <internal-name>jesusCircumcision</internal-name> <translation>Jesu Beschneidung</translation> + <properties> + <property id="type">statisch</property> + </properties> </holiday> <holiday> http://cvs.php.net/diff.php/pear/Date_Holidays/lang/Christian/en_EN.xml?r1=1.1&r2=1.2&ty=u Index: pear/Date_Holidays/lang/Christian/en_EN.xml diff -u pear/Date_Holidays/lang/Christian/en_EN.xml:1.1 pear/Date_Holidays/lang/Christian/en_EN.xml:1.2 --- pear/Date_Holidays/lang/Christian/en_EN.xml:1.1 Thu May 19 16:35:45 2005 +++ pear/Date_Holidays/lang/Christian/en_EN.xml Mon Aug 1 16:11:21 2005 @@ -6,6 +6,9 @@ <holiday> <internal-name>jesusCircumcision</internal-name> <translation>Circumcision of Jesus</translation> + <properties> + <property id="type">static</property> + </properties> </holiday> <holiday>
« previous php.pear.cvs (#33516) next »