123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- /*
- * This file is part of the symfony package.
- * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
- * (c) 2004-2006 Sean Kerr <sean@code-box.org>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- /**
- * sfParameterHolder provides a base class for managing parameters.
- *
- * Parameters, in this case, are used to extend classes with additional data
- * that requires no additional logic to manage.
- *
- * @package symfony
- * @subpackage util
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- * @author Sean Kerr <sean@code-box.org>
- * @version SVN: $Id: sfParameterHolder.class.php 10835 2008-08-13 11:58:38Z fabien $
- */
- class sfParameterHolder implements Serializable
- {
- protected $parameters = array();
- /**
- * The constructor for sfParameterHolder.
- */
- public function __construct()
- {
- }
- /**
- * Clears all parameters associated with this request.
- */
- public function clear()
- {
- $this->parameters = array();
- }
- /**
- * Retrieves a parameter.
- *
- * @param string $name A parameter name
- * @param mixed $default A default parameter value
- *
- * @return mixed A parameter value, if the parameter exists, otherwise null
- */
- public function & get($name, $default = null)
- {
- if (array_key_exists($name, $this->parameters))
- {
- $value = & $this->parameters[$name];
- }
- else
- {
- $value = sfToolkit::getArrayValueForPath($this->parameters, $name, $default);
- }
- return $value;
- }
- /**
- * Retrieves an array of parameter names.
- *
- * @return array An indexed array of parameter names
- */
- public function getNames()
- {
- return array_keys($this->parameters);
- }
- /**
- * Retrieves an array of parameters.
- *
- * @return array An associative array of parameters
- */
- public function & getAll()
- {
- return $this->parameters;
- }
- /**
- * Indicates whether or not a parameter exists.
- *
- * @param string $name A parameter name
- *
- * @return bool true, if the parameter exists, otherwise false
- */
- public function has($name)
- {
- if (array_key_exists($name, $this->parameters))
- {
- return true;
- }
- else
- {
- return sfToolkit::hasArrayValueForPath($this->parameters, $name);
- }
- return false;
- }
- /**
- * Remove a parameter.
- *
- * @param string $name A parameter name
- * @param mixed $default A default parameter value
- *
- * @return string A parameter value, if the parameter was removed, otherwise null
- */
- public function remove($name, $default = null)
- {
- $retval = $default;
- if (array_key_exists($name, $this->parameters))
- {
- $retval = $this->parameters[$name];
- unset($this->parameters[$name]);
- }
- else
- {
- $retval = sfToolkit::removeArrayValueForPath($this->parameters, $name, $default);
- }
- return $retval;
- }
- /**
- * Sets a parameter.
- *
- * If a parameter with the name already exists the value will be overridden.
- *
- * @param string $name A parameter name
- * @param mixed $value A parameter value
- */
- public function set($name, $value)
- {
- $this->parameters[$name] = $value;
- }
- /**
- * Sets a parameter by reference.
- *
- * If a parameter with the name already exists the value will be overridden.
- *
- * @param string $name A parameter name
- * @param mixed $value A reference to a parameter value
- */
- public function setByRef($name, & $value)
- {
- $this->parameters[$name] =& $value;
- }
- /**
- * Sets an array of parameters.
- *
- * If an existing parameter name matches any of the keys in the supplied
- * array, the associated value will be overridden.
- *
- * @param array $parameters An associative array of parameters and their associated values
- */
- public function add($parameters)
- {
- if (is_null($parameters))
- {
- return;
- }
- foreach ($parameters as $key => $value)
- {
- $this->parameters[$key] = $value;
- }
- }
- /**
- * Sets an array of parameters by reference.
- *
- * If an existing parameter name matches any of the keys in the supplied
- * array, the associated value will be overridden.
- *
- * @param array $parameters An associative array of parameters and references to their associated values
- */
- public function addByRef(& $parameters)
- {
- foreach ($parameters as $key => &$value)
- {
- $this->parameters[$key] =& $value;
- }
- }
- /**
- * Serializes the current instance.
- *
- * @return array Objects instance
- */
- public function serialize()
- {
- return serialize($this->parameters);
- }
- /**
- * Unserializes a sfParameterHolder instance.
- *
- * @param string $serialized A serialized sfParameterHolder instance
- */
- public function unserialize($serialized)
- {
- $this->parameters = unserialize($serialized);
- }
- }
|