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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 /**
  * @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;
 }
コード例 #4
0
 /**
  * @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());
 }
コード例 #5
0
 /**
  * @return string
  */
 public function getBundlePrefix()
 {
     return $this->manager->getBundlePrefix();
 }
コード例 #6
0
 /**
  * @param Request $request
  * @return ApiResource|bool
  */
 protected function getApiResource(Request $request)
 {
     $apiResourceName = $request->attributes->get('_api_resource');
     return $this->manager->getResource($apiResourceName);
 }