コード例 #1
0
 /**
  * Validates the $entity if the 'validate' key is not set to false in $options
  * If not empty it will construct a default validation object or get one with
  * the name passed in the key
  *
  * @param \Cake\ORM\Entity $entity The entity to validate
  * @param \ArrayObject $options The option for processing validation
  * @return bool true if the entity is valid, false otherwise
  */
 protected function _processValidation($entity, $options)
 {
     $type = is_string($options['validate']) ? $options['validate'] : 'default';
     $validator = $this->_table->validator($type);
     $pass = compact('entity', 'options', 'validator');
     $event = $this->_table->dispatchEvent('Model.beforeValidate', $pass);
     if ($event->isStopped()) {
         return (bool) $event->result;
     }
     if (!count($validator)) {
         return true;
     }
     $success = !$entity->validate($validator);
     $event = $this->_table->dispatchEvent('Model.afterValidate', $pass);
     if ($event->isStopped()) {
         $success = (bool) $event->result;
     }
     return $success;
 }