Source for file Container.php
Documentation is available at Container.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* Contains the Translation2_Container base class
* LICENSE: Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @category Internationalization
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2005 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @version CVS: $Id: Container.php,v 1.24 2008/02/02 18:03:04 quipo Exp $
* @link http://pear.php.net/package/Translation2
* Base class for Translation2 drivers/containers
* Extend this class to provide custom containers.
* Some containers are already bundled with the package.
* @category Internationalization
* @author Lorenzo Alberton <l.alberton@quipo.it>
* @copyright 2004-2005 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD License (3 Clause)
* @link http://pear.php.net/package/Translation2
* Additional options for the storage container
var $currentLang = array ();
* Has to be overwritten by each storage class
* Parse options passed to the container class
* @param array $array options
foreach ($array as $key => $value) {
* Get a valid langID or raise an error when no valid language is set
* @param string $langID language ID
* @return string language ID or PEAR_Error on error
function _getLangID ($langID)
if (!empty ($langID) || (0 === $langID)) {
if (!empty ($this->currentLang['id']) || (0 === $this->currentLang['id'])) {
return $this->currentLang['id'];
$msg = 'No valid language set. Use Translation2::setLang().';
* Set charset used to read/store the translations
* @param string $charset character set (encoding)
* @return PEAR_Error on error
return $this->storage->setCharset ($charset);
'method not implemented', __FUNCTION__ );
* Sets the current language
* @param string $langID language ID
* @return array language information
$this->getLangs(); //load available languages, if not loaded yet (ignore return value)
return $this->raiseError('unknown language: "'. $langID. '"',
$this->currentLang = $this->langs[$langID];
return $this->langs[$langID];
* @param string $format what must be returned
* @return mixed array with current lang data or null if not set yet
return isset ($this->currentLang['id']) ? $this->currentLang : null;
* Gets the array data for the lang
* @param string $langID language ID
* @param string $format what must be returned
* @return mixed array with lang data or null if not available
return isset ($langs[$langID]) ? $langs[$langID] : null;
* Gets the available languages
* @param string $format ['array' | 'ids' | 'names' | 'encodings']
//if not cached yet, fetch langs data from the container
if (empty ($this->langs) || !count($this->langs)) {
foreach ($this->langs as $aLang) {
$aLang['lang_id'] = $aLang['id'];
$tmp[$aLang['id']] = $aLang;
foreach ($this->langs as $aLang) {
foreach ($this->langs as $aLang) {
$tmp[] = $aLang['encoding'];
foreach ($this->langs as $aLang) {
$tmp[$aLang['id']] = $aLang['name'];
* Fetch the available langs if they're not cached yet.
* Containers should implement this method.
* @return PEAR_Error on error
return $this->raiseError('method "fetchLangs" not supported',
TRANSLATION_ERROR_METHOD_NOT_SUPPORTED );
* Returns an array of the strings in the selected page
* Containers should implement this method.
* @param string $pageID page/group ID
* @param string $langID language ID
function getPage($pageID = null , $langID = null )
return $this->raiseError('method "getPage" not supported',
TRANSLATION_ERROR_METHOD_NOT_SUPPORTED );
* Get a single item from the container, without caching the whole page
* Containers should implement this method.
* @param string $stringID string ID
* @param string $pageID page/group ID
* @param string $langID language ID
function getOne($stringID, $pageID = null , $langID = null )
return $this->raiseError('method "getOne" not supported',
TRANSLATION_ERROR_METHOD_NOT_SUPPORTED );
* Get the stringID for the given string
* @param string $string string
* @param string $pageID page/group ID
return $this->raiseError('method "getStringID" not supported',
TRANSLATION_ERROR_METHOD_NOT_SUPPORTED );
* @param string $msg error message
* @param int $code error code
* @param int $mode PEAR error mode
* @param int $option error severity
* @return void|PEAR_Error
function raiseError($msg, $code, $mode = PEAR_ERROR_TRIGGER , $option = E_USER_WARNING )
if (isset ($GLOBALS['_PEAR_default_error_mode'])) {
$mode = $GLOBALS['_PEAR_default_error_mode'];
if (isset ($GLOBALS['_PEAR_default_error_options'])) {
$option = $GLOBALS['_PEAR_default_error_options'];
if ($mode == PEAR_ERROR_RETURN ) {
return PEAR ::raiseError ($msg, $code, $mode, $option);
PEAR ::raiseError ($msg, $code, $mode, $option);
Documentation generated on Tue, 06 May 2008 06:00:16 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|