Ejemplo n.º 1
0
 public function create($name, $description, array $routes = null)
 {
     // check whether scope exists
     $condition = new Condition();
     $condition->equals('name', $name);
     $scope = $this->scopeTable->getOneBy($condition);
     if (!empty($scope)) {
         throw new StatusCode\BadRequestException('Scope already exists');
     }
     try {
         $this->scopeTable->beginTransaction();
         // create scope
         $this->scopeTable->create(array('name' => $name, 'description' => $description));
         // insert routes
         $scopeId = $this->scopeTable->getLastInsertId();
         $this->insertRoutes($scopeId, $routes);
         $this->scopeTable->commit();
     } catch (\Exception $e) {
         $this->scopeTable->rollBack();
         throw $e;
     }
 }