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 / Helper / DeclareVars.php
blobc3194851511a1c956535e8f6ad6e969139fa2776
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\Helper;
12 /**
13 * Helper for declaring default values of template variables
15 class DeclareVars extends AbstractHelper
17 /**
18 * The view object that created this helper object.
20 * @var \Zend\View\View
22 public $view;
24 /**
25 * Declare template vars to set default values and avoid notices when using strictVars
27 * Primarily for use when using {@link Zend_View_Abstract::strictVars() Zend_View strictVars()},
28 * this helper can be used to declare template variables that may or may
29 * not already be set in the view object, as well as to set default values.
30 * Arrays passed as arguments to the method will be used to set default
31 * values; otherwise, if the variable does not exist, it is set to an empty
32 * string.
34 * Usage:
35 * <code>
36 * $this->declareVars(
37 * 'varName1',
38 * 'varName2',
39 * array('varName3' => 'defaultValue',
40 * 'varName4' => array()
41 * )
42 * );
43 * </code>
45 * @param string|array variable number of arguments, all string names of variables to test
46 * @return void
48 public function __invoke()
50 $view = $this->getView();
51 $args = func_get_args();
52 foreach ($args as $key) {
53 if (is_array($key)) {
54 foreach ($key as $name => $value) {
55 $this->declareVar($name, $value);
57 } elseif (!isset($view->vars()->$key)) {
58 $this->declareVar($key);
63 /**
64 * Set a view variable
66 * Checks to see if a $key is set in the view object; if not, sets it to $value.
68 * @param string $key
69 * @param string $value Defaults to an empty string
70 * @return void
72 protected function declareVar($key, $value = '')
74 $view = $this->getView();
75 $vars = $view->vars();
76 if (!isset($vars->$key)) {
77 $vars->$key = $value;