public function create($priority, $name, $rateLimit, \DateInterval $timespan, array $allocations = null) { // check whether rate exists $condition = new Condition(); $condition->notEquals('status', Table\Rate::STATUS_DELETED); $condition->equals('name', $name); $app = $this->rateTable->getOneBy($condition); if (!empty($app)) { throw new StatusCode\BadRequestException('Rate already exists'); } try { $this->rateTable->beginTransaction(); // create rate $this->rateTable->create(array('status' => Table\Rate::STATUS_ACTIVE, 'priority' => $priority, 'name' => $name, 'rateLimit' => $rateLimit, 'timespan' => $timespan)); // get last insert id $rateId = $this->rateTable->getLastInsertId(); $this->handleAllocation($rateId, $allocations); $this->rateTable->commit(); } catch (\Exception $e) { $this->rateTable->rollBack(); throw $e; } }
public function create($status, $name, $email, $password, array $scopes = null) { // check whether user exists $condition = new Condition(); $condition->notEquals('status', Table\User::STATUS_DELETED); $condition->equals('name', $name); $user = $this->userTable->getOneBy($condition); if (!empty($user)) { throw new StatusCode\BadRequestException('User already exists'); } // check values $this->assertName($name); $this->assertEmail($email); $this->assertPassword($password); try { $this->userTable->beginTransaction(); // create user $this->userTable->create(array('provider' => ProviderInterface::PROVIDER_SYSTEM, 'status' => $status, 'name' => $name, 'email' => $email, 'password' => $password !== null ? \password_hash($password, PASSWORD_DEFAULT) : null, 'date' => new DateTime())); $userId = $this->userTable->getLastInsertId(); // add scopes $this->insertScopes($userId, $scopes); $this->userTable->commit(); } catch (\Exception $e) { $this->userTable->rollBack(); throw $e; } return $userId; }
public function create($userId, $status, $name, $url, $parameters = null, array $scopes = null) { // check whether app exists $condition = new Condition(); $condition->equals('userId', $userId); $condition->notEquals('status', Table\App::STATUS_DELETED); $condition->equals('name', $name); $app = $this->appTable->getOneBy($condition); if (!empty($app)) { throw new StatusCode\BadRequestException('App already exists'); } // parse parameters if ($parameters !== null) { $parameters = $this->parseParameters($parameters); } // create app $appKey = TokenGenerator::generateAppKey(); $appSecret = TokenGenerator::generateAppSecret(); try { $this->appTable->beginTransaction(); $this->appTable->create(array('userId' => $userId, 'status' => $status, 'name' => $name, 'url' => $url, 'parameters' => $parameters, 'appKey' => $appKey, 'appSecret' => $appSecret, 'date' => new DateTime())); $appId = $this->appTable->getLastInsertId(); if ($scopes !== null) { // insert scopes $this->insertScopes($appId, $scopes); } $this->appTable->commit(); } catch (\Exception $e) { $this->appTable->rollBack(); throw $e; } }