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