[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/storage/ -> sfStorage.class.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the symfony package.
   5   * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
   6   * (c) 2004-2006 Sean Kerr.
   7   * 
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  /**
  13   * sfStorage allows you to customize the way symfony stores its persistent data.
  14   *
  15   * @package    symfony
  16   * @subpackage storage
  17   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  18   * @author     Sean Kerr <skerr@mojavi.org>
  19   * @version    SVN: $Id: sfStorage.class.php 3329 2007-01-23 08:29:34Z fabien $
  20   */
  21  abstract class sfStorage
  22  {
  23    protected
  24      $parameterHolder = null,
  25      $context         = null;
  26  
  27    /**
  28     * Retrieves the current application context.
  29     *
  30     * @return sfContext A sfContext instance
  31     */
  32    public function getContext()
  33    {
  34      return $this->context;
  35    }
  36  
  37    /**
  38     * Initializes this Storage instance.
  39     *
  40     * @param sfContext A sfContext instance
  41     * @param array   An associative array of initialization parameters
  42     *
  43     * @return boolean true, if initialization completes successfully, otherwise false
  44     *
  45     * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfStorage
  46     */
  47    public function initialize($context, $parameters = array())
  48    {
  49      $this->context = $context;
  50  
  51      $this->parameterHolder = new sfParameterHolder();
  52      $this->getParameterHolder()->add($parameters);
  53    }
  54  
  55    /**
  56     * Retrieves a new Storage implementation instance.
  57     *
  58     * @param string A Storage implementation name
  59     *
  60     * @return Storage A Storage implementation instance
  61     *
  62     * @throws <b>sfFactoryException</b> If a storage implementation instance cannot be created
  63     */
  64    public static function newInstance($class)
  65    {
  66      // the class exists
  67      $object = new $class();
  68  
  69      if (!($object instanceof sfStorage))
  70      {
  71        // the class name is of the wrong type
  72        $error = 'Class "%s" is not of the type sfStorage';
  73        $error = sprintf($error, $class);
  74  
  75        throw new sfFactoryException($error);
  76      }
  77  
  78      return $object;
  79    }
  80  
  81    /**
  82     * Reads data from this storage.
  83     *
  84     * The preferred format for a key is directory style so naming conflicts can be avoided.
  85     *
  86     * @param string A unique key identifying your data
  87     *
  88     * @return mixed Data associated with the key
  89     *
  90     * @throws <b>sfStorageException</b> If an error occurs while reading data from this storage
  91     */
  92    abstract function & read($key);
  93  
  94    /**
  95     * Removes data from this storage.
  96     *
  97     * The preferred format for a key is directory style so naming conflicts can be avoided.
  98     *
  99     * @param string A unique key identifying your data
 100     *
 101     * @return mixed Data associated with the key
 102     *
 103     * @throws <b>sfStorageException</b> If an error occurs while removing data from this storage
 104     */
 105    abstract function & remove($key);
 106  
 107    /**
 108     * Executes the shutdown procedure.
 109     *
 110     * @throws <b>sfStorageException</b> If an error occurs while shutting down this storage
 111     */
 112    abstract function shutdown();
 113  
 114    /**
 115     * Writes data to this storage.
 116     *
 117     * The preferred format for a key is directory style so naming conflicts can be avoided.
 118     *
 119     * @param string A unique key identifying your data
 120     * @param mixed  Data associated with your key
 121     *
 122     * @throws <b>sfStorageException</b> If an error occurs while writing to this storage
 123     */
 124    abstract function write($key, &$data);
 125  
 126    /**
 127     * Retrieves the parameters from the storage.
 128     *
 129     * @return sfParameterHolder List of parameters
 130     */
 131    public function getParameterHolder()
 132    {
 133      return $this->parameterHolder;
 134    }
 135  
 136    /**
 137     * Retrieves a parameter from the validator.
 138     *
 139     * @param string Parameter name
 140     * @param mixed A default parameter
 141     * @param string Namespace for the current storage
 142     *
 143     * @return mixed A parameter value
 144     */
 145    public function getParameter($name, $default = null, $ns = null)
 146    {
 147      return $this->parameterHolder->get($name, $default, $ns);
 148    }
 149  
 150    /**
 151     * Indicates whether or not a parameter exist for the storage instance.
 152     *
 153     * @param string A parameter name
 154     * @param string A parameter namespace
 155     *
 156     * @return boolean true, if parameter exists, otherwise false
 157     */
 158    public function hasParameter($name, $ns = null)
 159    {
 160      return $this->parameterHolder->has($name, $ns);
 161    }
 162  
 163    /**
 164     * Sets a parameter for the current storage instance.
 165     *
 166     * @param string A parameter name
 167     * @param mixed A parameter value
 168     * @param string Namespace for the current storage
 169     */
 170    public function setParameter($name, $value, $ns = null)
 171    {
 172      return $this->parameterHolder->set($name, $value, $ns);
 173    }
 174  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7