Exemple #1
0
 /**
  * Get an instance of the action class to be used
  * @throws DrestException
  * @return AbstractAction $action
  */
 protected function getActionInstance()
 {
     if (!isset($this->service_action)) {
         if ($this->service_action_registry->hasServiceAction($this->matched_route)) {
             $this->service_action = $this->service_action_registry->getServiceAction($this->matched_route);
             $this->service_action->setService($this);
         } else {
             $this->service_action = $this->getDefaultAction();
         }
         if (!$this->service_action instanceof AbstractAction) {
             throw DrestException::actionClassNotAnInstanceOfActionAbstract(get_class($this->service_action));
         }
     }
     return $this->service_action;
 }
Exemple #2
0
 public function testRemovingFromRegistryByRouteAndHavingActionUsedForOtherRoute()
 {
     $registry = new Registry();
     $className = 'DrestTests\\Entities\\Typical\\User';
     $className2 = 'DrestTests\\Entities\\Typical\\User';
     $routeName = 'route_name';
     $routeName2 = 'route_name2';
     $serviceAction = new \DrestTests\Action\Custom();
     $registry->register($serviceAction, [$className . '::' . $routeName, $className2 . '::' . $routeName2]);
     $routeMetaData = new \Drest\Mapping\RouteMetaData();
     $routeMetaData->setClassMetaData(new \Drest\Mapping\ClassMetaData(new \ReflectionClass($className)));
     $routeMetaData->setName($routeName);
     $routeMetaData2 = new \Drest\Mapping\RouteMetaData();
     $routeMetaData2->setClassMetaData(new \Drest\Mapping\ClassMetaData(new \ReflectionClass($className2)));
     $routeMetaData2->setName($routeName2);
     $registry->unregisterByRoute($routeMetaData);
     $this->assertFalse($registry->hasServiceAction($routeMetaData));
     $this->assertTrue($registry->hasServiceAction($routeMetaData2));
     $this->assertSame($registry->getServiceAction($routeMetaData2), $serviceAction);
     $registry->unregisterByRoute($routeMetaData2);
     $this->assertFalse($registry->hasServiceAction($routeMetaData));
     $this->assertFalse($registry->hasServiceAction($routeMetaData2));
 }