ZendDbSchema
Schema management for Zend Framework
 All Classes Namespaces Functions Pages
Chain.php
1 <?php
30  implements Zend_Validate_Interface
31 {
37  protected $_validators = array();
38 
44  protected $_messages = array();
45 
52  protected $_errors = array();
53 
64  public function addValidator(Zend_Validate_Interface $validator, $breakChainOnFailure = false)
65  {
66  $this->_validators[] = array(
67  'instance' => $validator,
68  'breakChainOnFailure' => (boolean) $breakChainOnFailure
69  );
70  return $this;
71  }
72 
81  public function isValid($value)
82  {
83  $this->_messages = array();
84  $this->_errors = array();
85  $result = true;
86 
87  foreach ($this->_validators as $element) {
88  $validator = $element['instance'];
89  if ($validator->isValid($value)) {
90  continue;
91  }
92  $result = false;
93  $messages = $validator->getMessages();
94  $this->_messages = array_merge($this->_messages, $messages);
95  $this->_errors = array_merge($this->_errors, array_keys($messages));
96  if ($element['breakChainOnFailure']) {
97  break;
98  }
99  }
100  return $result;
101  }
102 
110  public function getMessages()
111  {
112  return $this->_messages;
113  }
114 
123  public function getErrors()
124  {
125  return $this->_errors;
126  }
127 }