Beispiel #1
0
 /**
  * @param string $email
  * @param string $nick
  * @param string $password
  * @param bool $add_created_timestamp
  * @throws \InvalidArgumentException
  * @return \Rocker\Object\User\UserInterface
  */
 public function createUser($email, $nick, $password, $add_created_timestamp = true)
 {
     if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
         throw new \InvalidArgumentException('No valid e-mail given');
     }
     /* @var \Rocker\Object\User\UserInterface $user */
     $user = parent::createObject($email);
     $user->setNick($nick);
     $user->setPassword($password);
     if ($add_created_timestamp) {
         $user->meta()->set('created', time());
     }
     $this->updateObject($user);
     return $user;
 }
 /**
  * @param \Rocker\Object\ObjectInterface $obj
  * @param \Rocker\Object\AbstractObjectFactory $factory
  * @param OperationResponse $response
  * @param ConnectionInterface $db
  * @param CacheInterface $cache
  * @param \Rocker\Server $server
  */
 protected function updateObject($obj, $factory, $response, $db, $cache, $server)
 {
     if (isset($_REQUEST['name'])) {
         $obj->setName($_REQUEST['name']);
     }
     if (isset($_REQUEST['meta']) && is_array($_REQUEST['meta'])) {
         $result = $this->addMetaFromRequestToObject($obj);
         if ($result !== null) {
             // Something not okay with the meta values
             $response->setStatus($result[0]);
             $response->setBody($result[1]);
             return;
         }
     }
     try {
         $factory->update($obj);
         $response->setBody($this->objectToArray($obj, $server, $db, $cache));
     } catch (DuplicationException $e) {
         $response->setStatus(409);
         $response->setBody(array('error' => $e->getMessage()));
     }
 }