public function setUp() { parent::setUp(); $resource = new ApiResource('posts', ['entity' => Post::class, 'filter' => PostFilter::class, 'pagination' => ['enabled' => true, 'limit' => 10], 'form_type' => DynamicFormType::class, 'identifier' => 'id']); $resource->setConfigName('posts'); $this->router = $this->client->getContainer()->get('router'); $resource->addAction(new Index($this->router)); $resource->addAction(new Create($this->router)); $this->manager = new ApiManager(); $this->manager->addResource($resource); }
public function setUp() { $router = $this->getMockBuilder(Router::class)->disableOriginalConstructor()->getMock(); $this->config = new ApiResource('posts', ['entity' => Post::class, 'filter' => null, 'pagination' => ['enabled' => false, 'limit' => 10], 'form_type' => DynamicFormType::class, 'identifier' => 'id']); $this->config->setConfigName('posts'); $this->config->addAction(new Index($router)); $this->config->addAction(new Create($router)); $this->config->addAction(new Show($router)); $this->config->addAction(new Update($router)); $this->config->addAction(new Delete($router)); $manager = new ApiManager(); $manager->addResource($this->config); }
/** * @param GetResponseForControllerResultEvent $event * @return \BiteCodes\RestApiGeneratorBundle\Api\Actions\Action|bool */ protected function getAction(GetResponseForControllerResultEvent $event) { $apiResourceName = $event->getRequest()->attributes->get('_api_resource'); $controllerName = $event->getRequest()->attributes->get('_controller'); $apiResource = $this->manager->getResource($apiResourceName); return $apiResource ? $apiResource->getAction(ApiHelper::getActionClassFromControllerName($controllerName)) : false; }
/** * @param $routeName * @param ApiResource $resource * @return string */ private function getSection($routeName, ApiResource $resource) { $prefixPos = strlen($resource->getBundlePrefix() . '.'); $nextDot = strpos($routeName, '.', $prefixPos); $resourceName = substr($routeName, $prefixPos, $nextDot - $prefixPos); $parentResource = $this->manager->getResource($resourceName); return ucwords($parentResource->getName()); }
/** * @return string */ public function getBundlePrefix() { return $this->manager->getBundlePrefix(); }
/** * @param Request $request * @return ApiResource|bool */ protected function getApiResource(Request $request) { $apiResourceName = $request->attributes->get('_api_resource'); return $this->manager->getResource($apiResourceName); }