Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / View / Variables.php
blobf917389ec70ac03f102bb2397bbb9b0ab66dee7c
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\View;
12 use ArrayObject;
14 /**
15 * Abstract class for Zend_View to help enforce private constructs.
17 * @todo Allow specifying string names for manager, filter chain, variables
18 * @todo Move escaping into variables object
19 * @todo Move strict variables into variables object
21 class Variables extends ArrayObject
23 /**
24 * Strict variables flag; when on, undefined variables accessed in the view
25 * scripts will trigger notices
27 * @var bool
29 protected $strictVars = false;
31 /**
32 * Constructor
34 * @param array $variables
35 * @param array $options
37 public function __construct(array $variables = array(), array $options = array())
39 parent::__construct(
40 $variables,
41 ArrayObject::ARRAY_AS_PROPS,
42 'ArrayIterator'
45 $this->setOptions($options);
48 /**
49 * Configure object
51 * @param array $options
52 * @return Variables
54 public function setOptions(array $options)
56 foreach ($options as $key => $value) {
57 switch (strtolower($key)) {
58 case 'strict_vars':
59 $this->setStrictVars($value);
60 break;
61 default:
62 // Unknown options are considered variables
63 $this[$key] = $value;
64 break;
67 return $this;
70 /**
71 * Set status of "strict vars" flag
73 * @param bool $flag
74 * @return Variables
76 public function setStrictVars($flag)
78 $this->strictVars = (bool) $flag;
79 return $this;
82 /**
83 * Are we operating with strict variables?
85 * @return bool
87 public function isStrict()
89 return $this->strictVars;
92 /**
93 * Assign many values at once
95 * @param array|object $spec
96 * @return Variables
97 * @throws Exception\InvalidArgumentException
99 public function assign($spec)
101 if (is_object($spec)) {
102 if (method_exists($spec, 'toArray')) {
103 $spec = $spec->toArray();
104 } else {
105 $spec = (array) $spec;
108 if (!is_array($spec)) {
109 throw new Exception\InvalidArgumentException(sprintf(
110 'assign() expects either an array or an object as an argument; received "%s"',
111 gettype($spec)
114 foreach ($spec as $key => $value) {
115 $this[$key] = $value;
118 return $this;
122 * Get the variable value
124 * If the value has not been defined, a null value will be returned; if
125 * strict vars on in place, a notice will also be raised.
127 * Otherwise, returns _escaped_ version of the value.
129 * @param mixed $key
130 * @return mixed
132 public function offsetGet($key)
134 if (!$this->offsetExists($key)) {
135 if ($this->isStrict()) {
136 trigger_error(sprintf(
137 'View variable "%s" does not exist', $key
138 ), E_USER_NOTICE);
140 return null;
143 $return = parent::offsetGet($key);
145 // If we have a closure/functor, invoke it, and return its return value
146 if (is_object($return) && is_callable($return)) {
147 $return = call_user_func($return);
150 return $return;
154 * Clear all variables
156 * @return void
158 public function clear()
160 $this->exchangeArray(array());