1: <?php
2:
3: /**
4: * This file contains the abstract validator class.
5: *
6: * @package Core
7: * @subpackage Validation
8: * @version SVN Revision $Rev:$
9: *
10: * @author Murat Purc <murat@purc.de>
11: * @copyright four for business AG <www.4fb.de>
12: * @license http://www.contenido.org/license/LIZENZ.txt
13: * @link http://www.4fb.de
14: * @link http://www.contenido.org
15: */
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: /**
20: * Abstract validator.
21: *
22: * @package Core
23: * @subpackage Validation
24: */
25: abstract class cValidatorAbstract {
26:
27: /**
28: * List of options, depends by used validator
29: *
30: * @var array
31: */
32: protected $_options = array();
33:
34: /**
35: * List of validations errors
36: *
37: * @var array
38: */
39: protected $_errors = array();
40:
41: /**
42: * Options setter, merges passed options with previous set options.
43: *
44: * @param array $options
45: */
46: public function setOptions(array $options) {
47: $this->_options = array_merge($this->_options, $options);
48: }
49:
50: /**
51: * Single option setter.
52: *
53: * @param string $name
54: * @param mixed $value
55: */
56: public function setOption($name, $value) {
57: $this->_options[$name] = $value;
58: }
59:
60: /**
61: * Option getter.
62: *
63: * @param string $name
64: * @return mixed|NULL
65: */
66: public function getOption($name) {
67: return isset($this->_options[$name]) ? $this->_options[$name] : NULL;
68: }
69:
70: /**
71: * Returns list of validations errors
72: *
73: * @return array
74: */
75: public function getErrors() {
76: return $this->_errors;
77: }
78:
79: /**
80: * Adds a error.
81: *
82: * @param string $message
83: * @param mixed $code
84: */
85: protected function addError($message, $code) {
86: $this->_errors[] = (object) array('message' => $message, 'code' => $code);
87: }
88:
89: /**
90: * Validates the passed value.
91: *
92: * @param mixed $value
93: * @return bool
94: */
95: public function isValid($value) {
96: return $this->_isValid($value);
97: }
98:
99: /**
100: * Abstract isValid method, which has to be implemented by childs
101: *
102: * @param mixed $value
103: * @return bool
104: */
105: abstract protected function _isValid($value);
106: }
107: