PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/application/libraries/Zend/View/Helper/DeclareVars.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 95 lines | 25 code | 4 blank | 66 comment | 4 complexity | a77bd57d97b62425ebb25732243bc872 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @version $Id: DeclareVars.php 23775 2011-03-01 17:25:24Z ralph $
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /** Zend_View_Helper_Abstract.php */
  23. require_once 'Zend/View/Helper/Abstract.php';
  24. /**
  25. * Helper for declaring default values of template variables
  26. *
  27. * @package Zend_View
  28. * @subpackage Helper
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_View_Helper_DeclareVars extends Zend_View_Helper_Abstract
  33. {
  34. /**
  35. * The view object that created this helper object.
  36. * @var Zend_View
  37. */
  38. public $view;
  39. /**
  40. * Declare template vars to set default values and avoid notices when using strictVars
  41. *
  42. * Primarily for use when using {@link Zend_View_Abstract::strictVars() Zend_View strictVars()},
  43. * this helper can be used to declare template variables that may or may
  44. * not already be set in the view object, as well as to set default values.
  45. * Arrays passed as arguments to the method will be used to set default
  46. * values; otherwise, if the variable does not exist, it is set to an empty
  47. * string.
  48. *
  49. * Usage:
  50. * <code>
  51. * $this->declareVars(
  52. * 'varName1',
  53. * 'varName2',
  54. * array('varName3' => 'defaultValue',
  55. * 'varName4' => array()
  56. * )
  57. * );
  58. * </code>
  59. *
  60. * @param string|array variable number of arguments, all string names of variables to test
  61. * @return void
  62. */
  63. public function declareVars()
  64. {
  65. $args = func_get_args();
  66. foreach($args as $key) {
  67. if (is_array($key)) {
  68. foreach ($key as $name => $value) {
  69. $this->_declareVar($name, $value);
  70. }
  71. } else if (!isset($view->$key)) {
  72. $this->_declareVar($key);
  73. }
  74. }
  75. }
  76. /**
  77. * Set a view variable
  78. *
  79. * Checks to see if a $key is set in the view object; if not, sets it to $value.
  80. *
  81. * @param string $key
  82. * @param string $value Defaults to an empty string
  83. * @return void
  84. */
  85. protected function _declareVar($key, $value = '')
  86. {
  87. if (!isset($this->view->$key)) {
  88. $this->view->$key = $value;
  89. }
  90. }
  91. }