. //============================================================================ /** * @copyright Francois Laupretre * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0 * @category phool * @package phool */ //============================================================================ namespace Phool; abstract class VarContainer { protected $vars=array(); //------------------ public static function boolVal($val) { return ($val ? 'Y' : ''); } //------------------ public function valIsSet($vname) { return array_key_exists($vname,$this->vars); } //------------------ public function valIsTrue($vname) { return ($this->valIsSet($vname) ? ($this->val($vname) != '') : false); } //------------------ public function __get($vname) { return $this->val($vname); } //------------------ // Difference with __get() method. This one allows to retrieve any variable name, even containing characters forbidden // in variable names (like '/'). public function val($vname) { if (!$this->valIsSet($vname)) throw new \Exception("$vname: Variable not set"); return $this->vars[$vname]; } //------------------ public function valArray() { return $this->vars; } //------------------ public function setVal($name,$value) { $this->vars[$name]=trim($value); } //------------------ } ?>