PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/web/concrete/core/helpers/validation/error.php

https://github.com/elizad/concrete5
PHP | 77 lines | 33 code | 8 blank | 36 comment | 6 complexity | 8f5e35667b891f73651a952350f5a90c MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause
  1. <?
  2. /**
  3. * @package Helpers
  4. * @subpackage Validation
  5. * @author Andrew Embler <andrew@concrete5.org>
  6. * @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
  7. * @license http://www.concrete5.org/license/ MIT License
  8. */
  9. /**
  10. * Helper elements for dealing with errors in Concrete
  11. * @package Helpers
  12. * @subpackage Validation
  13. * @author Andrew Embler <andrew@concrete5.org>
  14. * @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
  15. * @license http://www.concrete5.org/license/ MIT License
  16. */
  17. defined('C5_EXECUTE') or die("Access Denied.");
  18. class Concrete5_Helper_Validation_Error {
  19. protected $error = array();
  20. /**
  21. * this method is called by the Loader::helper to clean up the instance of this object
  22. * resets the class scope variables
  23. * @return void
  24. */
  25. public function reset() {
  26. $this->error = array();
  27. }
  28. /**
  29. * Adds an error object or exception to the internal error array
  30. * @param Exception | string $e
  31. * @return void
  32. */
  33. public function add($e) {
  34. if ($e instanceof ValidationErrorHelper) {
  35. $this->error = array_merge($e->getList(), $this->error);
  36. } else if (is_object($e) && ($e instanceof Exception)) {
  37. $this->error[] = $e->getMessage();
  38. } else {
  39. $this->error[] = $e;
  40. }
  41. }
  42. /**
  43. * Returns a list of errors in the error helper
  44. * @return array
  45. */
  46. public function getList() {
  47. return $this->error;
  48. }
  49. /**
  50. * Returns whether or not this error helper has more than one error registered within it.
  51. * @return bool
  52. */
  53. public function has() {
  54. return (count($this->error) > 0);
  55. }
  56. /**
  57. * Outputs the HTML of an error list, with the correct style attributes/classes. This is a convenience method.
  58. */
  59. public function output() {
  60. if ($this->has()) {
  61. print '<ul class="ccm-error">';
  62. foreach($this->getList() as $error) {
  63. print '<li>' . $error . '</li>';
  64. }
  65. print '</ul>';
  66. }
  67. }
  68. }
  69. ?>