Source for file State.php

Documentation is available at State.php

  1. <?php
  2.     /**
  3.      * The state manager class
  4.      * 
  5.      * @copyright Copyright (c) 2007 Mirchev Ideas Ltd. All rights reserved.
  6.      * @package MIPHPF
  7.      */
  8.     
  9.     /**
  10.      * Saves and restores the state base class
  11.      * 
  12.      * @copyright Copyright (c) 2007 Mirchev Ideas Ltd. All rights reserved.
  13.      * @package MIPHPF
  14.      */
  15.     class miState {
  16.         protected $_category;
  17.         protected $_stateVars = array();
  18.         
  19.         protected $_persistVars = array();
  20.         
  21.         /**
  22.          * Constucts the state manager class
  23.          *
  24.          * @param string $category 
  25.          */
  26.         public function __construct($category '')
  27.         {
  28.             $this->_category = $category;
  29.         }
  30.         
  31.         public function setDefaultCategory($category)
  32.         {
  33.             $this->_category = $category;
  34.         }
  35.         
  36.         /**
  37.          * Get the names of variables to be persisted
  38.          *
  39.          * @return array 
  40.          */
  41.         public function getPersistVars()
  42.         {
  43.             return $this->_persistVars[$this->_category];
  44.         }
  45.         
  46.         /**
  47.          * Set the names of variables to be persisted
  48.          *
  49.          * @param array $persistVars 
  50.          */
  51.         public function setPersistVars($persistVars)
  52.         {
  53.             $this->_persistVars[$this->_category$persistVars;
  54.         }
  55.         
  56. //        public function selectCategory($category)
  57. //        {
  58. //            $this->_category = $category;
  59. //        }
  60.         
  61. //        public function get($name)
  62. //        {
  63. //            return $this->_stateVars[$this->_category][$name];
  64. //        }
  65. //        
  66. //        public function set($name, $value)
  67. //        {
  68. //            $this->_stateVars[$this->_category][$name] = $value;
  69. //        }
  70.         
  71.         public function getArray($category false)
  72.         {
  73.             if ($category == false)
  74.                 $category $this->_category;
  75.             
  76.             if (!isset($this->_stateVars[$category]))
  77.                 return array();
  78.             return $this->_stateVars[$category];
  79.         }
  80.         
  81.         public function setArray($values$category false)
  82.         {
  83.             if ($category == false)
  84.                 $category $this->_category;
  85.             
  86.             if (!isset($this->_stateVars[$category])) {
  87.                 $this->_stateVars[$category$values;
  88.                 return;
  89.             }
  90.             $this->_stateVars[$categoryarray_merge($this->_stateVars[$category]$values);
  91.         }
  92.         
  93.         public function restoreState()
  94.         {
  95.             $this->_stateVars[$this->_category$_REQUEST;
  96.         }
  97.         
  98.         public function saveState()
  99.         {
  100.         }
  101.         
  102.         public function getStateUrlParams()
  103.         {
  104.             if (!isset($this->_stateVars[$this->_category]))
  105.                 return '';
  106.             
  107.             // If there are no persist vars for the category don't persist
  108.             if (!isset($this->_persistVars[$this->_category]))
  109.                 return '';
  110.             
  111.             $vars array_combine($this->_persistVars[$this->_category]$this->_persistVars[$this->_category]);
  112.             $stateVars array_intersect_key($this->_stateVars[$this->_category]$vars);
  113.             if (empty($stateVars))
  114.                 return '';
  115.             return http_build_query($stateVars);
  116.         }
  117.     }
  118. ?>

Documentation generated on Thu, 08 May 2008 16:57:40 +0300 by phpDocumentor 1.4.1