Source code for file /joomla/registry/registry.php
Documentation is available at registry.php
* @version $Id: registry.php 6472 2007-02-03 10:47:26Z pasamio $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
jimport( 'joomla.registry.format' );
* @package Joomla.Framework
* - actually an array of namespace objects
* @param string $namespace Default registry namespace
* Returns a reference to a global JRegistry object, only creating it
* if it doesn't already exist.
* This method must be invoked as:
* <pre>$registry =& JRegistry::getInstance($id[, $namespace]);</pre>
* @param string $id An ID for the registry instance
* @param string $namespace The default namespace for the registry object [optional]
* @return object The JRegistry object.
if (!isset
($instances)) {
if (empty ($instances[$id])) {
* @param string $namespace Name of the namespace to create
* @return boolean True on success
$this->_registry[$namespace] =
array('data' =>
new stdClass());
* Get the list of namespaces
* @return array List of namespaces
* @param string $regpath Registry path (e.g. joomla.content.showauthor)
* @param mixed $default Optional default value
* @return mixed Value of entry or null
function getValue($regpath, $default=
null)
// Explode the registry path into an array
if ($nodes =
explode('.', $regpath))
//$namespace = array_shift($nodes);
$ns =
& $this->_registry[$namespace]['data'];
$pathNodes =
count($nodes) -
1;
//for ($i = 0; $i < $pathNodes; $i ++) {
for ($i =
1; $i <
$pathNodes; $i ++
) {
if(isset
($ns->$nodes[$i])) {
$result =
$ns->$nodes[$i];
* @param string $regpath Registry Path (e.g. joomla.content.showauthor)
* @param mixed $value Value of entry
* @return mixed Value of old value or boolean false if operation failed
// Explode the registry path into an array
$ns =
& $this->_registry[$namespace]['data'];
$pathNodes =
count($nodes) -
1;
for ($i =
0; $i <
$pathNodes; $i ++
)
// If any node along the registry path does not exist, create it
if (!isset
($ns->$nodes[$i])) {
$ns->$nodes[$i] =
new stdClass();
// Get the old value if exists so we can return it
@$retval =
& $ns->$nodes[$i];
$ns->$nodes[$i] =
& $value;
* Load a associative array of values into the default namespace
* @param array $array Associative array of value to load
* @param string $namepsace The name of the namespace
* @return boolean True on success
function loadArray($array, $namespace =
null)
// If namespace is not set, get the default namespace
if ($namespace ==
null) {
// If namespace does not exist, make it and load the data
// Load the variables into the registry's default namespace.
foreach ($array as $k =>
$v)
$this->_registry[$namespace]['data']->$k =
$v;
* Load the public variables of the object into the default namespace.
* @param object $object The object holding the public vars to load
* @param string $namespace Namespace to load the INI string into [optional]
* @return boolean True on success
// If namespace is not set, get the default namespace
if ($namespace ==
null) {
// If namespace does not exist, make it and load the data
* We want to leave groups that are already in the namespace and add the
* groups loaded into the namespace. This overwrites any existing group
if (substr($k, 0,1) !=
'_' ||
$k ==
'_name') {
$this->_registry[$namespace]['data']->$k =
$v;
* Load the contents of a file into the registry
* @param string $file Path to file to load
* @param string $format Format of the file [optional: defaults to INI]
* @param string $namespace Namespace to load the INI string into [optional]
* @return boolean True on success
function loadFile($file, $format =
'INI', $namespace =
null)
// Load a file into the given namespace [or default namespace if not given]
$handler =
& $this->_loadFormat($format);
// If namespace is not set, get the default namespace
if ($namespace ==
null) {
// Get the contents of the file
// If namespace does not exist, make it and load the data
$this->_registry[$namespace]['data'] =
$handler->stringToObject($data);
// Get the data in object format
$ns =
$handler->stringToObject($data);
* We want to leave groups that are already in the namespace and add the
* groups loaded into the namespace. This overwrites any existing group
$this->_registry[$namespace]['data']->$k =
$v;
* Load an XML string into the registry into the given namespace [or default if a namespace is not given]
* @param string $data XML formatted string to load into the registry
* @param string $namespace Namespace to load the XML string into [optional]
* @return boolean True on success
function loadXML($data, $namespace =
null)
// Load a string into the given namespace [or default namespace if not given]
// If namespace is not set, get the default namespace
if ($namespace ==
null) {
// If namespace does not exist, make it and load the data
$this->_registry[$namespace]['data'] =
& $handler->stringToObject($data);
// Get the data in object format
$ns =
& $handler->stringToObject($data);
* We want to leave groups that are already in the namespace and add the
* groups loaded into the namespace. This overwrites any existing group
$this->_registry[$namespace]['data']->$k =
$v;
* Load an INI string into the registry into the given namespace [or default if a namespace is not given]
* @param string $data INI formatted string to load into the registry
* @param string $namespace Namespace to load the INI string into [optional]
* @return boolean True on success
function loadINI($data, $namespace =
null)
// Load a string into the given namespace [or default namespace if not given]
// If namespace is not set, get the default namespace
if ($namespace ==
null) {
// If namespace does not exist, make it and load the data
$this->_registry[$namespace]['data'] =
& $handler->stringToObject($data);
// Get the data in object format
$ns =
$handler->stringToObject($data);
* We want to leave groups that are already in the namespace and add the
* groups loaded into the namespace. This overwrites any existing group
$this->_registry[$namespace]['data']->$k =
$v;
* Merge a JRegistry object into this one
* @param object $source Source JRegistry object ot merge
* @return boolean True on success
if (is_a($source, 'JRegistry')) {
$sns =
$source->getNameSpaces();
// If namespace does not exist, make it and load the data
// Load the variables into the registry's default namespace.
foreach ($source->toArray($ns) as $k =>
$v) {
* Get a namespace in a given string format
* @param string $format Format to return the string in
* @param string $namespace Namespace to return [optional: null returns the default namespace]
* @param mixed $params Parameters used by the formatter, see formatters for more info
* @return string Namespace in string format
function toString($format =
'INI', $namespace =
null, $params =
null)
// Return a namespace in a given format
// If namespace is not set, get the default namespace
if ($namespace ==
null) {
$ns =
& $this->_registry[$namespace]['data'];
return $handler->objectToString($ns, $params);
* Transforms a namespace to an array
* @param string $namespace Namespace to return [optional: null returns the default namespace]
* @return array An associative array holding the namespace data
function toArray($namespace =
null)
// If namespace is not set, get the default namespace
if ($namespace ==
null) {
$ns =
& $this->_registry[$namespace]['data'];
* Transforms a namespace to an object
* @param string $namespace Namespace to return [optional: null returns the default namespace]
* @return object An an object holding the namespace data
// If namespace is not set, get the default namespace
if ($namespace ==
null) {
$ns =
& $this->_registry[$namespace]['data'];
* Return the relevant JRegistryFormat object
* @param string $format The format to return
* @return object Formatting object
function &_loadFormat($format)
if(jimport('joomla.registry.format.'.
$lformat))
$class =
'JRegistryFormat'.
$format;