/**
  * @Route("/extra.{_format}", name="_extra_noname", defaults={"_format"="html"}),
  * @Route("/extra/{name}.{_format}", name="_extra_name", defaults={"_format"="html"})
  * @View()
  */
 public function indexAction($name = null)
 {
     if (!$name) {
         return ViewClass::createRedirect('http://liip.ch');
     }
     return array('name' => $name);
 }
Example #2
0
 /**
  * @param Request $request
  * @param $lastNewPaymentId
  *
  * @return Response
  */
 public function prepareCaptureAction(Request $request, $lastNewPaymentId)
 {
     $configuration = $this->requestConfigurationFactory->create($this->paymentMetadata, $request);
     $payment = $this->paymentRepository->find($lastNewPaymentId);
     Assert::notNull($payment);
     $request->getSession()->set('sylius_order_id', $payment->getOrder()->getId());
     $captureToken = $this->getTokenFactory()->createCaptureToken($payment->getMethod()->getGateway(), $payment, $configuration->getParameters()->get('redirect[route]', null, true), $configuration->getParameters()->get('redirect[parameters]', [], true));
     $view = View::createRedirect($captureToken->getTargetUrl());
     return $this->viewHandler->handle($configuration, $view);
 }
 /**
  * Create an organisation
  * @var Request $request
  * @return View|FormInterface
  */
 public function cpostAction(Request $request)
 {
     $organisation = new Organisation();
     $form = $this->formFactory->createNamed('', new OrganisationType(), $organisation);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->manager->persist($organisation);
         $this->manager->flush($organisation);
         $url = $this->router->generate('get_organisation', array('organisation' => $organisation->getId()));
         return View::createRedirect($url, Codes::HTTP_CREATED);
     }
     return $form;
 }
Example #4
0
 /**
  * Create a user for an organisation
  * @var Organisation $organisation
  * @var Request $request
  * @return View|FormInterface
  */
 public function cpostAction(Organisation $organisation, Request $request)
 {
     $user = new User($organisation);
     $form = $this->formFactory->createNamed('', 'Nmpolo\\RestBundle\\Form\\UserType', $user);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->manager->persist($user);
         $this->manager->flush($user);
         $url = $this->router->generate('get_organisation_user', array('organisation' => $organisation->getId(), 'user' => $user->getId()));
         return View::createRedirect($url, Codes::HTTP_CREATED);
     }
     return $form;
 }
Example #5
0
 public function testSetLocation()
 {
     $url = 'users';
     $code = 500;
     $view = View::createRedirect($url, $code);
     $this->assertAttributeEquals($url, 'location', $view);
     $this->assertAttributeEquals(null, 'route', $view);
     $this->assertEquals($code, $view->getResponse()->getStatusCode());
     $view = new View();
     $location = 'location';
     $view->setLocation($location);
     $this->assertEquals($location, $view->getLocation());
 }
Example #6
0
 /**
  * Create a user for an Groups
  * @var Groups $Groups
  * @var Request $request
  * @return View|FormInterface
  */
 public function cpostAction(Groups $Groups, Request $request)
 {
     $user = new User($Groups);
     $form = $this->formFactory->createNamed('', new UserType(), $user);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->manager->persist($user);
         $this->manager->flush($user);
         $url = $this->router->generate('get_Groups_user', array('Groups' => $Groups->getId(), 'user' => $user->getId()));
         return View::createRedirect($url, Codes::HTTP_CREATED);
     }
     return $form;
 }
 /**
  * Collection post action
  * @var Request $request
  * @return View|array
  */
 public function postAction(Request $request)
 {
     $challenge = new Challenge();
     $form = $this->createForm(new ChallengeType(), $challenge, array('csrf_protection' => false));
     $json_data = json_decode($request->getContent(), true);
     //get the response data as array
     $form->submit($json_data);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($challenge);
         $em->flush();
         $url = $this->generateUrl('bf_rest_api_challenges_get', array('id' => $challenge->getId()));
         return View::createRedirect($url, Codes::HTTP_CREATED);
     }
     return array('form' => $form);
 }
Example #8
0
 /**
  * Creates a Redirect view.
  *
  * Convenience method to allow for a fluent interface.
  *
  * @param string $url
  * @param int    $statusCode
  * @param array  $headers
  *
  * @return View
  */
 protected function redirectView($url, $statusCode = Codes::HTTP_FOUND, array $headers = array())
 {
     return View::createRedirect($url, $statusCode, $headers);
 }
Example #9
0
 /**
  * Convenience method to allow for a fluent interface.
  *
  * @param string  $url
  * @param integer $statusCode
  * @param array   $headers
  *
  * @deprecated To be removed in FOSRestBundle 2.0.0. Use View::createRedirect instead.
  */
 public static function create($url, $statusCode = Codes::HTTP_FOUND, array $headers = array())
 {
     return View::createRedirect($url, $statusCode, $headers);
 }
Example #10
0
 /**
  * Creates a Redirect view.
  *
  * Convenience method to allow for a fluent interface.
  *
  * @param string $url
  * @param int    $statusCode
  * @param array  $headers
  *
  * @return View
  */
 protected function redirectView($url, $statusCode = Response::HTTP_FOUND, array $headers = [])
 {
     return View::createRedirect($url, $statusCode, $headers);
 }
Example #11
0
 /**
  * @param array  $parameters
  * @param OrmPersistible|null   $object
  * @param string $method
  *
  * @return View
  */
 protected function process(array $parameters, $object, $method = 'PUT')
 {
     $class = $this->getTypeClassString();
     $type = class_exists($this->getTypeClassString()) ? new $class() : $this->getTypeClassString();
     $bag = array();
     list($object, $bag, $parameters) = $this->preSubmit($object, $bag, $parameters);
     $form = $this->formfactory->create($type, $object);
     $form->submit($this->camelizeParamers($parameters), 'PATCH' !== $method);
     $url = $this->getRouteName();
     /** @var OrmPersistible $object */
     if ($form->isValid()) {
         $code = $object->getId() ? Codes::HTTP_NO_CONTENT : Codes::HTTP_CREATED;
         list($object, ) = $this->preFlush($object, $bag);
         $this->getEm()->persist($object);
         $this->getEm()->flush();
         $view = View::createRedirect($this->router->generate($url, array('id' => $object->getId())), $code);
         return $view;
     }
     $this->logger->error((string) $form->getErrors(false, true) . " PARAMETERS: " . json_encode($parameters));
     return View::create($form, Codes::HTTP_BAD_REQUEST);
 }
Example #12
0
 /**
  * @param Request $request
  * @param mixed $tokenValue
  *
  * @return Response
  */
 public function prepareCaptureAction(Request $request, $tokenValue)
 {
     $configuration = $this->requestConfigurationFactory->create($this->orderMetadata, $request);
     /** @var OrderInterface $order */
     $order = $this->orderRepository->findOneByTokenValue($tokenValue);
     if (null === $order) {
         throw new NotFoundHttpException(sprintf('Order with token "%s" does not exist.', $tokenValue));
     }
     $request->getSession()->set('sylius_order_id', $order->getId());
     $options = $configuration->getParameters()->get('redirect');
     $payment = $order->getLastPayment(PaymentInterface::STATE_NEW);
     if (null === $payment) {
         throw new NotFoundHttpException(sprintf('Order with token "%s" has no pending payments.', $tokenValue));
     }
     $captureToken = $this->getTokenFactory()->createCaptureToken($payment->getMethod()->getGateway(), $payment, isset($options['route']) ? $options['route'] : null, isset($options['parameters']) ? $options['parameters'] : []);
     $view = View::createRedirect($captureToken->getTargetUrl());
     return $this->viewHandler->handle($configuration, $view);
 }
 /**
  * Put action
  * @var Request $request
  * @var integer $id Id of the user
  * @return View|array
  */
 public function putAction(Request $request, $id)
 {
     $user = $this->getEntity($id);
     $form = $this->createForm(new UserType(), $user, array('csrf_protection' => false));
     $json_data = json_decode($request->getContent(), true);
     //get the response data as array
     $form->submit($json_data);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($user);
         $em->flush();
         return View::createRedirect($url, Codes::HTTP_NO_CONTENT);
     }
     return array('form' => $form);
 }