Source for file Context.php

Documentation is available at Context.php

  1. <?php
  2.  
  3. /**
  4.  * Registry object that contains information about the current context.
  5.  * @warning Is a bit buggy when variables are set to null: it thinks
  6.  *           they don't exist! So use false instead, please.
  7.  * @note Since the variables Context deals with may not be objects,
  8.  *        references are very important here! Do not remove!
  9.  */
  10. {
  11.     
  12.     /**
  13.      * Private array that stores the references.
  14.      */
  15.     private $_storage array();
  16.     
  17.     /**
  18.      * Registers a variable into the context.
  19.      * @param $name String name
  20.      * @param $ref Reference to variable to be registered
  21.      */
  22.     public function register($name&$ref{
  23.         if (isset($this->_storage[$name])) {
  24.             trigger_error("Name $name produces collision, cannot re-register",
  25.                           E_USER_ERROR);
  26.             return;
  27.         }
  28.         $this->_storage[$name=$ref;
  29.     }
  30.     
  31.     /**
  32.      * Retrieves a variable reference from the context.
  33.      * @param $name String name
  34.      * @param $ignore_error Boolean whether or not to ignore error
  35.      */
  36.     public function &get($name$ignore_error false{
  37.         if (!isset($this->_storage[$name])) {
  38.             if (!$ignore_error{
  39.                 trigger_error("Attempted to retrieve non-existent variable $name",
  40.                               E_USER_ERROR);
  41.             }
  42.             $var null// so we can return by reference
  43.             return $var;
  44.         }
  45.         return $this->_storage[$name];
  46.     }
  47.     
  48.     /**
  49.      * Destorys a variable in the context.
  50.      * @param $name String name
  51.      */
  52.     public function destroy($name{
  53.         if (!isset($this->_storage[$name])) {
  54.             trigger_error("Attempted to destroy non-existent variable $name",
  55.                           E_USER_ERROR);
  56.             return;
  57.         }
  58.         unset($this->_storage[$name]);
  59.     }
  60.     
  61.     /**
  62.      * Checks whether or not the variable exists.
  63.      * @param $name String name
  64.      */
  65.     public function exists($name{
  66.         return isset($this->_storage[$name]);
  67.     }
  68.     
  69.     /**
  70.      * Loads a series of variables from an associative array
  71.      * @param $context_array Assoc array of variables to load
  72.      */
  73.     public function loadArray($context_array{
  74.         foreach ($context_array as $key => $discard{
  75.             $this->register($key$context_array[$key]);
  76.         }
  77.     }
  78.     
  79. }

Documentation generated on Thu, 19 Jun 2008 18:48:57 -0400 by phpDocumentor 1.4.2