[ Index ]

PHP Cross Reference of phool

title

Body

[close]

/Phool/ -> VarContainer.php (source)

   1  <?php
   2  //============================================================================
   3  // This program is free software: you can redistribute it and/or modify
   4  // it under the terms of the GNU Lesser General Public License (LGPL) as
   5  // published by the Free Software Foundation, either version 3 of the License,
   6  // or (at your option) any later version.
   7  //
   8  // This program is distributed in the hope that it will be useful,
   9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11  // GNU Lesser General Public License for more details.
  12  //
  13  // You should have received a copy of the GNU Lesser General Public License
  14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15  //============================================================================
  16  /**
  17  * @copyright Francois Laupretre <phool@tekwire.net>
  18  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0
  19  * @category phool
  20  * @package phool
  21  */
  22  //============================================================================
  23  
  24  namespace Phool;
  25  
  26  abstract class VarContainer
  27  {
  28  
  29  protected $vars=array();
  30  
  31  //------------------
  32  
  33  public static function boolVal($val)
  34  {
  35  return ($val ? 'Y' : '');
  36  }
  37  
  38  //------------------
  39  
  40  public function valIsSet($vname)
  41  {
  42  return array_key_exists($vname,$this->vars);
  43  }
  44  
  45  //------------------
  46  
  47  public function valIsTrue($vname)
  48  {
  49  return ($this->valIsSet($vname) ? ($this->val($vname) != '') : false);
  50  }
  51  
  52  //------------------
  53  
  54  public function __get($vname)
  55  {
  56  return $this->val($vname);
  57  }
  58  
  59  //------------------
  60  // Difference with __get() method. This one allows to retrieve any variable name, even containing characters forbidden
  61  // in variable names (like '/').
  62  
  63  public function val($vname)
  64  {
  65  if (!$this->valIsSet($vname)) throw new \Exception("$vname: Variable not set");
  66  return $this->vars[$vname];
  67  }
  68  
  69  //------------------
  70  
  71  public function valArray()
  72  {
  73  return $this->vars;
  74  }
  75  
  76  //------------------
  77  
  78  public function setVal($name,$value)
  79  {
  80  $this->vars[$name]=trim($value);
  81  }
  82  
  83  //------------------
  84  }
  85  ?>


Generated: Thu Jun 4 19:17:11 2015 Cross-referenced by PHPXref 0.7.1