Ejemplo n.º 1
0
 /**
  * save
  *
  * @param DataInterface|Entity $data
  *
  * @return  DataInterface|Entity
  *
  * @throws  \LogicException
  * @throws  \UnexpectedValueException
  * @throws  \Windwalker\Record\Exception\NoResultException
  * @throws  \InvalidArgumentException
  * @throws  \RuntimeException
  */
 public function save(DataInterface $data)
 {
     // Prepare Record object, primary keys and dump input data
     $record = $this->getRecord();
     $keys = array_filter((array) $this->getKeyName(true));
     // Fix because Record return empty string
     $dumped = $data->dump(true);
     // Let's check if primary exists, do action for update.
     $conditions = array_intersect_key($dumped, array_flip($keys));
     if (array_filter($conditions)) {
         try {
             $record->load($conditions);
         } catch (NoResultException $e) {
             throw new NoResultException('Try to update a non-exists record to database.', $e->getCode(), $e);
         }
     }
     $record->bind($dumped);
     $this->prepareRecord($record);
     $record->validate()->store($this->updateNulls);
     $this->postSaveHook($record);
     $data->bind($record->dump(true));
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * validate
  *
  * @param  DataInterface $data
  *
  * @return  void
  *
  * @throws ValidateFailException
  */
 protected function validate(DataInterface $data)
 {
     $validator = new EmailValidator();
     if (!$validator->validate($data->email)) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.email.invalid'));
     }
     $form = $this->model->getForm('registration', 'user');
     $this->model->validate($data->dump(), $form);
     if (!$data->password) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.entered'));
     }
     if ($data->password != $data->password2) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.match'));
     }
     unset($data->password2);
 }
Ejemplo n.º 3
0
 /**
  * validate
  *
  * @param   DataInterface|Entity  $data
  *
  * @return  void
  *
  * @throws ValidateFailException
  */
 protected function validate(DataInterface $data)
 {
     $model = $this->getModel();
     if ($model instanceof FormAwareRepositoryInterface) {
         $model->validate($data->dump(true));
     }
 }