Testing_DocTest
[ class tree: Testing_DocTest ] [ index: Testing_DocTest ] [ all elements ]

Source for file Registry.php

Documentation is available at Registry.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * This file is part of the PEAR Testing_DocTest package.
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This source file is subject to the MIT license that is available
  11.  * through the world-wide-web at the following URI:
  12.  * http://opensource.org/licenses/mit-license.php
  13.  *
  14.  * @category  Testing
  15.  * @package   Testing_DocTest
  16.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  17.  * @copyright 2008 David JEAN LOUIS
  18.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  19.  * @version   CVS: $Id$
  20.  * @link      http://pear.php.net/package/Testing_DocTest
  21.  * @since     File available since release 0.1.0
  22.  * @filesource
  23.  */
  24.  
  25. /**
  26.  * A simple Registry that will allow Doctest components to share options and
  27.  * instances in order to achieve loose coupling.
  28.  *
  29.  * <code>
  30.  *
  31.  * Testing_DocTest_Registry::singleton()->somevar = 'foo';
  32.  * var_dump(isset(Testing_DocTest_Registry::singleton()->somevar));
  33.  * echo Testing_DocTest_Registry::singleton()->somevar . "\n";
  34.  * unset(Testing_DocTest_Registry::singleton()->somevar);
  35.  * echo Testing_DocTest_Registry::singleton()->somevar;
  36.  *
  37.  * // expects:
  38.  * // bool(true)
  39.  * // foo
  40.  * //
  41.  * </code>
  42.  *
  43.  * @category  Testing
  44.  * @package   Testing_DocTest
  45.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  46.  * @copyright 2008 David JEAN LOUIS
  47.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  48.  * @version   Release: 0.6.0
  49.  * @link      http://pear.php.net/package/Testing_DocTest
  50.  * @since     Class available since release 0.1.0
  51.  */
  52. {
  53.     // properties {{{
  54.  
  55.     /**
  56.      * The singleton instance.
  57.      *
  58.      * @var object $_instance Testing_DocTest_Registry instance
  59.      * @access private
  60.      */
  61.     private static $_instance = null;
  62.  
  63.     /**
  64.      * The registry items array.
  65.      *
  66.      * @var array $_items 
  67.      * @access private
  68.      */
  69.     private $_items = array();
  70.  
  71.     // }}}
  72.     // __construct() {{{
  73.  
  74.     /**
  75.      * Constructor, can not be called outside this class.
  76.      *
  77.      * @access protected
  78.      * @return void 
  79.      */
  80.     protected function __construct(
  81.     {
  82.     }
  83.  
  84.     // }}}
  85.     // singleton() {{{
  86.  
  87.     /**
  88.      * Singleton constructor.
  89.      *
  90.      * @return object an instance of Testing_DocTest_Registry
  91.      * @access public
  92.      */
  93.     public static function singleton()
  94.     {
  95.         if (self::$_instance === null{
  96.             self::$_instance = new self();
  97.         }
  98.         return self::$_instance;
  99.     }
  100.  
  101.     // }}}
  102.     // __set() {{{
  103.  
  104.     /**
  105.      * Overloaded setter.
  106.      *
  107.      * @param string $name  name of property
  108.      * @param mixed  $value value of property
  109.      *
  110.      * @return void 
  111.      * @access public
  112.      */
  113.     public function __set($name$value)
  114.     {
  115.         $this->_items[$name$value;
  116.     }
  117.  
  118.     // }}}
  119.     // __get() {{{
  120.  
  121.     /**
  122.      * Overloaded getter.
  123.      *
  124.      * @param string $name name of property
  125.      *
  126.      * @return mixed 
  127.      * @access public
  128.      */
  129.     public function __get($name)
  130.     {
  131.         if (isset($this->_items[$name])) {
  132.             return $this->_items[$name];
  133.         }
  134.         return null;
  135.     }
  136.  
  137.     // }}}
  138.     // __isset() {{{
  139.  
  140.  
  141.     /**
  142.      * Overloaded for isset() function.
  143.      *
  144.      * @param string $name name of property
  145.      *
  146.      * @return boolean 
  147.      * @access public
  148.      */   
  149.     public function __isset($name)
  150.     {
  151.         return isset($this->_items[$name]);
  152.     }
  153.  
  154.     // }}}
  155.     // __unset() {{{
  156.  
  157.     /**
  158.      * Overloaded for unset() function.
  159.      *
  160.      * @param string $name name of property
  161.      *
  162.      * @return void 
  163.      * @access public
  164.      */   
  165.     public function __unset($name)
  166.     {
  167.         unset($this->_items[$name]);
  168.     }
  169.  
  170.     // }}}
  171. }

Documentation generated on Mon, 11 Mar 2019 15:52:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.