/**
  * @inheritdoc
  */
 public function execute(Request $request, DataSourceInterface $resource, $identifier)
 {
     if (!$resource->delete(intval($identifier))) {
         throw new NotFoundHttpException();
     }
     return ActionResult::simple(200, ['status' => 'success']);
 }
 function it_should_throw_if_instance_not_found(DataSourceInterface $dataSource)
 {
     $data = ['name' => 'foo'];
     $request = Request::create('/user/1', 'PUT');
     $request->attributes->set(AuthorizationListener::API_REQUEST_PAYLOAD, $data);
     $dataSource->update(1, $data)->willReturn(null);
     $this->shouldThrow('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException')->during('execute', [$request, $dataSource, 1]);
 }
 /**
  * @inheritdoc
  */
 public function execute(Request $request, DataSourceInterface $resource, $identifier)
 {
     $instance = $resource->update($identifier, $request->attributes->get(AuthorizationListener::API_REQUEST_PAYLOAD));
     if (is_null($instance)) {
         throw new NotFoundHttpException();
     }
     return ActionResult::instance(200, $resource->read($identifier));
 }
示例#4
0
 /**
  * @inheritdoc
  */
 public function execute(Request $request, DataSourceInterface $resource, $identifier)
 {
     $instance = $resource->read($identifier);
     if (is_null($instance)) {
         throw new NotFoundHttpException();
     }
     return ActionResult::instance(200, $instance);
 }
 function it_should_index_via_dataSource(DataSourceInterface $dataSource)
 {
     $request = new Request(['limit' => 1, 'offset' => 1]);
     $dataSource->index(1, 1, null, null)->willReturn([]);
     $result = $this->execute($request, $dataSource);
     $result->shouldHaveType('Im0rtality\\ApiBundle\\Actions\\ActionResult');
     $result->getStatusCode()->shouldBe(200);
     $result->getResult()->shouldBe([]);
     $result->getType()->shouldBe(ActionResult::COLLECTION);
 }
 function it_should_create_via_dataSource(DataSourceInterface $dataSource)
 {
     $data = ['name' => 'foo'];
     $request = Request::create('/user', 'POST');
     $request->attributes->set(AuthorizationListener::API_REQUEST_PAYLOAD, $data);
     $dataSource->create($data)->willReturn(array_merge($data, ['id' => 1]));
     $result = $this->execute($request, $dataSource, 1);
     $result->shouldHaveType('Im0rtality\\ApiBundle\\Actions\\ActionResult');
     $result->getStatusCode()->shouldBe(201);
     $result->getResult()->shouldBe(array_merge($data, ['id' => 1]));
     $result->getType()->shouldBe(ActionResult::INSTANCE);
 }
 /**
  * @inheritdoc
  */
 public function execute(Request $request, DataSourceInterface $resource)
 {
     return ActionResult::instance(201, $resource->create($request->attributes->get(AuthorizationListener::API_REQUEST_PAYLOAD)));
 }
 /**
  * @inheritdoc
  */
 public function execute(Request $request, DataSourceInterface $resource)
 {
     return ActionResult::simple(200, ['count' => $resource->count()]);
 }
 /**
  * @inheritdoc
  */
 public function execute(Request $request, DataSourceInterface $resource)
 {
     return ActionResult::collection(200, $resource->index($request->query->get('limit'), $request->query->get('offset'), $request->query->get('orderBy'), $request->query->get('order')));
 }
 /**
  * Creates parametrized instance of configured resource
  *
  * @param string $resource Resource identifier
  * @return DataSourceInterface
  */
 public function create($resource)
 {
     return $this->dataSource->setResource($resource);
 }
 function it_should_throw_if_instance_not_found(DataSourceInterface $dataSource)
 {
     $request = Request::create('/user/1', 'GET');
     $dataSource->read(1)->willReturn(null);
     $this->shouldThrow('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException')->during('execute', [$request, $dataSource, 1]);
 }