Source for file class.mpglobals.php

Documentation is available at class.mpglobals.php

  1. <?php
  2. /**
  3.  * Includes globals array access class.
  4.  *
  5.  * @author      Murat Purc <murat@purc.de>
  6.  * @copyright   © Murat Purc 2008
  7.  * @date        07.10.2008
  8.  * @package     Contenido
  9.  * @subpackage  Globals
  10.  */
  11.  
  12.  
  13. defined('CON_FRAMEWORK'or die('Illegal call');
  14.  
  15.  
  16. include_once('class.mparraymanager.php');
  17.  
  18.  
  19. /**
  20.  * Globals array ($GLOBALS) manager class. Provides another way to access (reading/writing) to
  21.  * globals array.
  22.  *
  23.  * Number of access deepness to the array structure depends on extended class 'mpArrayManager'.
  24.  * This is by default up to 4 levels, e. g. $arr['one']['two']['three']['four'].
  25.  *
  26.  * The whole purpose of this class is to replace usage of superglobal $GLOBALS and the global
  27.  * declaration of variables (global $foobar;) within functions.
  28.  * @see http://www.php.net/manual/en/language.variables.scope.php
  29.  *
  30.  *
  31.  *  Usage:
  32.  *  <code>
  33.  *  // example globals content
  34.  *  $GLOBALS['key']['subkey']['anotherkey'] = 123;
  35.  *
  36.  *  // example access (assuming that access delemiter is /)
  37.  *  $glob = mpGlobals::getInstance();
  38.  *  echo $glob->get('key/subkey/anotherkey');
  39.  *
  40.  *  // example for setting the content
  41.  *  $glob->set('key/subkey/anotherkey', 321);
  42.  *  </code>
  43.  *
  44.  * @author      Murat Purc <murat@purc.de>
  45.  * @package     Contenido
  46.  * @subpackage  Globals
  47.  */
  48. class mpGlobals extends mpArrayManager implements mpIArrayManager {
  49.  
  50.     /**
  51.      * Constructor, stores the reference to $GLOBALS into member variable _aData.
  52.      */
  53.     private function __construct({
  54.         $this->_aData = $GLOBALS;
  55.     }
  56.  
  57.     /**
  58.      * Returns a instance of mpGlobals (singleton implementation)
  59.      *
  60.      * @return  mpGlobals 
  61.      */
  62.     public static function getInstance({
  63.         if (self::$_instance == null{
  64.             self::$_instance new mpGlobals();
  65.         }
  66.         return self::$_instance;
  67.     }
  68.  
  69. }

Documentation generated on Sun, 08 Feb 2009 22:00:47 +0100 by phpDocumentor 1.4.1