コード例 #1
0
 /**
  * Returns data and options prepared to validate and marshall.
  *
  * @param array $data The data to prepare.
  * @param array $options The options passed to this marshaller.
  * @return array An array containing prepared data and options.
  */
 protected function _prepareDataAndOptions($data, $options)
 {
     $options += ['validate' => true];
     $tableName = $this->_table->alias();
     if (isset($data[$tableName])) {
         $data = $data[$tableName];
     }
     $data = new \ArrayObject($data);
     $options = new \ArrayObject($options);
     $this->_table->dispatchEvent('Model.beforeMarshal', compact('data', 'options'));
     return [(array) $data, (array) $options];
 }
コード例 #2
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;
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function dispatchEvent($name, $data = null, $subject = null)
 {
     $data['table'] = $this;
     return parent::dispatchEvent($name, $data, $subject);
 }