Exemplo n.º 1
0
 /**
  * @param Request $request
  *
  * @return RedirectResponse
  */
 public function applyStateMachineTransitionAction(Request $request)
 {
     $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
     $this->isGrantedOr403($configuration, ResourceActions::UPDATE);
     $resource = $this->findOr404($configuration);
     $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource);
     if ($event->isStopped() && !$configuration->isHtmlRequest()) {
         throw new HttpException($event->getErrorCode(), $event->getMessage());
     }
     if ($event->isStopped()) {
         $this->flashHelper->addFlashFromEvent($configuration, $event);
         return $this->redirectHandler->redirectToResource($configuration, $resource);
     }
     if (!$this->stateMachine->can($configuration, $resource)) {
         throw new BadRequestHttpException();
     }
     $this->stateMachine->apply($configuration, $resource);
     $this->manager->flush();
     $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource);
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create($resource, Response::HTTP_OK));
     }
     $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource);
     return $this->redirectHandler->redirectToResource($configuration, $resource);
 }
Exemplo n.º 2
0
 /**
  * @param Request $request
  *
  * @return Response
  */
 public function afterCaptureAction(Request $request)
 {
     $configuration = $this->requestConfigurationFactory->create($this->paymentMetadata, $request);
     $token = $this->getHttpRequestVerifier()->verify($request);
     $status = new GetStatus($token);
     $this->payum->getGateway($token->getGatewayName())->execute($status);
     $resolveNextRoute = new ResolveNextRoute($status->getFirstModel());
     $this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute);
     $this->getHttpRequestVerifier()->invalidate($token);
     return $this->viewHandler->handle($configuration, View::createRouteRedirect($resolveNextRoute->getRouteName(), $resolveNextRoute->getRouteParameters()));
 }
Exemplo n.º 3
0
 /**
  * @param Request $request
  * @param integer $movement
  *
  * @return RedirectResponse
  */
 protected function move(Request $request, $movement)
 {
     $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
     $resource = $this->findOr404($configuration);
     $position = $configuration->getSortablePosition();
     $accessor = PropertyAccess::createPropertyAccessor();
     $accessor->setValue($resource, $position, $accessor->getValue($resource, $position) + $movement);
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create($resource, 204));
     }
     $this->flashHelper->addSuccessFlash($configuration, 'move', $resource);
     return $this->redirectHandler->redirectToIndex($configuration, $resource);
 }
Exemplo n.º 4
0
 /**
  * @param Request $request
  *
  * @return Response
  */
 public function afterCaptureAction(Request $request)
 {
     $configuration = $this->requestConfigurationFactory->create($this->orderMetadata, $request);
     $token = $this->getHttpRequestVerifier()->verify($request);
     $status = new GetStatus($token);
     $this->payum->getGateway($token->getGatewayName())->execute($status);
     $resolveNextRoute = new ResolveNextRoute($status->getFirstModel());
     $this->payum->getGateway($token->getGatewayName())->execute($resolveNextRoute);
     $this->getHttpRequestVerifier()->invalidate($token);
     if (PaymentInterface::STATE_NEW !== $status->getValue()) {
         $request->getSession()->getBag('flashes')->add('info', sprintf('sylius.payment.%s', $status->getValue()));
     }
     return $this->viewHandler->handle($configuration, View::createRouteRedirect($resolveNextRoute->getRouteName(), $resolveNextRoute->getRouteParameters()));
 }
Exemplo n.º 5
0
 /**
  * @param Request $request
  * @param int $movement
  *
  * @return RedirectResponse
  */
 protected function move(Request $request, $movement)
 {
     $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
     $resource = $this->findOr404($configuration);
     $position = $configuration->getSortablePosition();
     $accessor = PropertyAccess::createPropertyAccessor();
     $accessor->setValue($resource, $position, $accessor->getValue($resource, $position) + $movement);
     $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource);
     $this->manager->flush();
     $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource);
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
     }
     $this->flashHelper->addSuccessFlash($configuration, 'move', $resource);
     return $this->redirectHandler->redirectToIndex($configuration, $resource);
 }
Exemplo n.º 6
0
 /**
  * @param Request $request
  * @param string $transition
  * @param string $graph
  *
  * @return RedirectResponse
  */
 public function updateStateAction(Request $request, $transition, $graph)
 {
     $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
     $resource = $this->findOr404($configuration);
     $stateMachine = $this->get('sm.factory')->get($resource, $graph);
     if (!$stateMachine->can($transition)) {
         throw new NotFoundHttpException(sprintf('The requested transition %s cannot be applied on the given %s with graph %s.', $transition, $this->metadata->getName(), $graph));
     }
     $stateMachine->apply($transition);
     $this->manager->flush();
     if (!$configuration->isHtmlRequest()) {
         return $this->viewHandler->handle($configuration, View::create($resource, 204));
     }
     $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource);
     return $this->redirectHandler->redirectToReferer($configuration);
 }
Exemplo n.º 7
0
 function it_deletes_a_resource_and_returns_204_for_non_html_requests(MetadataInterface $metadata, RequestConfigurationFactoryInterface $requestConfigurationFactory, RequestConfiguration $configuration, AuthorizationCheckerInterface $authorizationChecker, ViewHandlerInterface $viewHandler, RepositoryInterface $repository, SingleResourceProviderInterface $singleResourceProvider, ResourceInterface $resource, EventDispatcherInterface $eventDispatcher, ResourceControllerEvent $event, Request $request, Response $response)
 {
     $metadata->getApplicationName()->willReturn('sylius');
     $metadata->getName()->willReturn('product');
     $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
     $configuration->hasPermission()->willReturn(true);
     $configuration->getPermission(ResourceActions::DELETE)->willReturn('sylius.product.delete');
     $authorizationChecker->isGranted($configuration, 'sylius.product.delete')->willReturn(true);
     $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
     $configuration->isHtmlRequest()->willReturn(false);
     $eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource)->willReturn($event);
     $event->isStopped()->willReturn(false);
     $repository->remove($resource)->shouldBeCalled();
     $eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource)->shouldBeCalled();
     $expectedView = View::create(null, 204);
     $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
     $this->deleteAction($request)->shouldReturn($response);
 }
 function it_applies_state_machine_transition_on_resource_and_returns_200_for_non_html_requests(MetadataInterface $metadata, RequestConfigurationFactoryInterface $requestConfigurationFactory, RequestConfiguration $configuration, AuthorizationCheckerInterface $authorizationChecker, ViewHandlerInterface $viewHandler, StateMachineInterface $stateMachine, ObjectManager $manager, RepositoryInterface $repository, SingleResourceProviderInterface $singleResourceProvider, ResourceInterface $resource, EventDispatcherInterface $eventDispatcher, ResourceControllerEvent $event, Request $request, Response $response)
 {
     $metadata->getApplicationName()->willReturn('sylius');
     $metadata->getName()->willReturn('product');
     $requestConfigurationFactory->create($metadata, $request)->willReturn($configuration);
     $configuration->hasPermission()->willReturn(true);
     $configuration->getPermission(ResourceActions::UPDATE)->willReturn('sylius.product.update');
     $authorizationChecker->isGranted($configuration, 'sylius.product.update')->willReturn(true);
     $singleResourceProvider->get($configuration, $repository)->willReturn($resource);
     $configuration->isHtmlRequest()->willReturn(false);
     $eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource)->willReturn($event);
     $event->isStopped()->willReturn(false);
     $stateMachine->can($configuration, $resource)->willReturn(true);
     $stateMachine->apply($configuration, $resource)->shouldBeCalled();
     $manager->flush()->shouldBeCalled();
     $eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource)->shouldBeCalled();
     $expectedView = View::create($resource, 200);
     $viewHandler->handle($configuration, Argument::that($this->getViewComparingCallback($expectedView)))->willReturn($response);
     $this->applyStateMachineTransitionAction($request)->shouldReturn($response);
 }