/** * Check submitted data for validator. You can toggle whether the data validated is bound to the form, or if * it is posted. You can also submit your own array of data, although this will be overwritten if $fromPost * is set to to true * * @return bool Returns true if data is valid */ public function isValid($addToFlash = true) { // Ensure validation is not run twice as this can cause field data to go missing second time round if ($this->_valid === null) { if (!$this->getPost()) { $this->_valid = false; return $this->_valid; } $this->submitForm(); // because symfony removes invalid data, but we actually need this data for the validator // to display the right error messages, we need to give the validator an array with both the // new symfony-form-data and the post-data :'( $data = array_replace_recursive($this->getPost(), $this->getForm()->getData()); $valid = $this->_validator->validate($data); $valid = $valid ? $this->getForm()->isValid() : $valid; if ($addToFlash && !$this->_addedToFlash) { $this->addMessagesToFlash(); } $this->_valid = $valid && $this->getForm()->isValid(); } return $this->_valid; }
public function validateAgainst(array $var, Validator $validator) { return $validator->validate($var); }