PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 157 lines | 61 code | 17 blank | 79 comment | 4 complexity | df037d93bf2f42d5414030ab9b01481a 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. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: FormErrors.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * Abstract class for extension
  24. */
  25. require_once 'Zend/View/Helper/FormElement.php';
  26. /**
  27. * Helper to render errors for a form element
  28. *
  29. * @category Zend
  30. * @package Zend_View
  31. * @subpackage Helper
  32. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_View_Helper_FormErrors extends Zend_View_Helper_FormElement
  36. {
  37. /**
  38. * @var Zend_Form_Element
  39. */
  40. protected $_element;
  41. /**#@+
  42. * @var string Element block start/end tags and separator
  43. */
  44. protected $_htmlElementEnd = '</li></ul>';
  45. protected $_htmlElementStart = '<ul%s><li>';
  46. protected $_htmlElementSeparator = '</li><li>';
  47. /**#@-*/
  48. /**
  49. * Render form errors
  50. *
  51. * @param string|array $errors Error(s) to render
  52. * @param array $options
  53. * @return string
  54. */
  55. public function formErrors($errors, array $options = null)
  56. {
  57. $escape = true;
  58. if (isset($options['escape'])) {
  59. $escape = (bool) $options['escape'];
  60. unset($options['escape']);
  61. }
  62. if (empty($options['class'])) {
  63. $options['class'] = 'errors';
  64. }
  65. $start = $this->getElementStart();
  66. if (strstr($start, '%s')) {
  67. $attribs = $this->_htmlAttribs($options);
  68. $start = sprintf($start, $attribs);
  69. }
  70. if ($escape) {
  71. foreach ($errors as $key => $error) {
  72. $errors[$key] = $this->view->escape($error);
  73. }
  74. }
  75. $html = $start
  76. . implode($this->getElementSeparator(), (array) $errors)
  77. . $this->getElementEnd();
  78. return $html;
  79. }
  80. /**
  81. * Set end string for displaying errors
  82. *
  83. * @param string $string
  84. * @return Zend_View_Helper_FormErrors
  85. */
  86. public function setElementEnd($string)
  87. {
  88. $this->_htmlElementEnd = (string) $string;
  89. return $this;
  90. }
  91. /**
  92. * Retrieve end string for displaying errors
  93. *
  94. * @return string
  95. */
  96. public function getElementEnd()
  97. {
  98. return $this->_htmlElementEnd;
  99. }
  100. /**
  101. * Set separator string for displaying errors
  102. *
  103. * @param string $string
  104. * @return Zend_View_Helper_FormErrors
  105. */
  106. public function setElementSeparator($string)
  107. {
  108. $this->_htmlElementSeparator = (string) $string;
  109. return $this;
  110. }
  111. /**
  112. * Retrieve separator string for displaying errors
  113. *
  114. * @return string
  115. */
  116. public function getElementSeparator()
  117. {
  118. return $this->_htmlElementSeparator;
  119. }
  120. /**
  121. * Set start string for displaying errors
  122. *
  123. * @param string $string
  124. * @return Zend_View_Helper_FormErrors
  125. */
  126. public function setElementStart($string)
  127. {
  128. $this->_htmlElementStart = (string) $string;
  129. return $this;
  130. }
  131. /**
  132. * Retrieve start string for displaying errors
  133. *
  134. * @return string
  135. */
  136. public function getElementStart()
  137. {
  138. return $this->_htmlElementStart;
  139. }
  140. }