Example #1
0
 public function showAction($contentDocument, Request $request)
 {
     $configuration = $this->requestConfigurationFactory->createSimple($request);
     $viewerFactory = $this->get('viewer.factory');
     $viewer = $viewerFactory->create($configuration, null, $contentDocument, null, 'base');
     return $this->viewHandler->handle($viewer->createView());
 }
 /**
  * @Route("/{id}", name="icap_badge_api_badge_get", requirements={"id" = "\d+"}, defaults={"_format" = "json"})
  */
 public function getAction($id)
 {
     /** @var \Icap\BadgeBundle\Entity\Badge $badge */
     $badge = $this->badgeRepository->find($id);
     if (null === $badge) {
         throw new NotFoundHttpException('Badge not found');
     }
     $view = View::create()->setStatusCode(200)->setData($badge);
     return $this->viewHandler->handle($view);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function handle(RequestConfiguration $requestConfiguration, View $view)
 {
     if (!$requestConfiguration->isHtmlRequest()) {
         $this->restViewHandler->setExclusionStrategyGroups($requestConfiguration->getSerializationGroups());
         if ($version = $requestConfiguration->getSerializationVersion()) {
             $this->restViewHandler->setExclusionStrategyVersion($version);
         }
         $view->getSerializationContext()->enableMaxDepthChecks();
     }
     return $this->restViewHandler->handle($view);
 }
Example #4
0
 /**
  * @ApiDoc
  *
  * @param integer $objectId            
  * @throws NotFoundHttpException
  */
 public function getUserAction($userId = 0)
 {
     /* @var $model \App\ModuleObjectsBundle\Model\MapObjectModel */
     $model = $this->container->get('app_module_user.model.user');
     $data = $model->findOneById($userId);
     if (null === $data) {
         throw new NotFoundHttpException();
     }
     $view = new View();
     $view->setData($data);
     $context = new SerializationContext();
     $context->setGroups(array('.all', 'user.get'));
     $view->setSerializationContext($context);
     return $this->viewHandler->handle($view);
 }
 public function jsonpAction()
 {
     $data = array('foo' => 'bar');
     $view = new View($data);
     $view->setFormat('jsonp');
     return $this->viewHandler->handle($view);
 }
Example #6
0
 /**
  * Return a JSON encoded scalar array of index names.
  *
  * @return Response
  */
 public function indexesAction()
 {
     return $this->viewHandler->handle(View::create(array_map(function ($indexName) {
         $indexConfiguration = $this->indexConfigurationProvider->getIndexConfiguration($indexName);
         return $indexConfiguration ?: new IndexConfiguration($indexName);
     }, $this->getAllowedIndexes())));
 }
Example #7
0
 /**
  * Saves a new existing snippet.
  *
  * @param Request $request
  * @param string $uuid
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function putSnippetAction(Request $request, $uuid)
 {
     $this->initEnv($request);
     $data = $request->request->all();
     $mapperRequest = ContentMapperRequest::create()->setType('snippet')->setTemplateKey($this->getRequired($request, 'template'))->setUuid($uuid)->setLocale($this->languageCode)->setUserId($this->getUser()->getId())->setData($data)->setState(intval($request->get('state', StructureInterface::STATE_PUBLISHED)));
     $snippet = $this->contentMapper->saveRequest($mapperRequest);
     $view = View::create($this->decorateSnippet($snippet->toArray(), $this->languageCode));
     return $this->viewHandler->handle($view);
 }
 /**
  * Returns all the content navigation items for a given alias.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function cgetAction(Request $request)
 {
     try {
         $alias = $request->get('alias');
         if (!$alias) {
             throw new RestException('The alias attribute is required to load the content navigation');
         }
         $options = $request->query->all();
         $contentNavigationItems = $this->contentNavigationRegistry->getNavigationItems($alias, $options);
         $view = View::create($contentNavigationItems);
     } catch (ContentNavigationAliasNotFoundException $exc) {
         $restException = new RestException($exc->getMessage(), 0, $exc);
         $view = View::create($restException->toArray(), 404);
     } catch (RestException $exc) {
         $view = View::create($exc->toArray(), 400);
     }
     return $this->viewHandler->handle($view);
 }
 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $route = $request->attributes->get('_route');
     if (empty($route)) {
         $route = $request->attributes->get('_master_request_route');
     }
     if (!$this->provider->isItemWhitelisted($route)) {
         $notFoundException = new NotFoundHttpException('Sorry, the page that you requested was not found.');
         $statusCode = $notFoundException->getStatusCode();
         $parameters = ['status_code' => $statusCode, 'status_text' => Response::$statusTexts[$statusCode], 'currentContent' => '', 'exception' => FlattenException::create($notFoundException), 'logger' => $this->logger];
         $view = View::create($parameters);
         $view->setFormat(self::VIEW_FORMAT);
         $view->setTemplate($this->findTemplate($request, $statusCode, $this->kernel->isDebug()));
         $response = $this->viewHandler->handle($view);
         $event->setResponse($response);
     }
 }
Example #10
0
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  * @dataProvider getCallbackFailureDataProvider
  */
 public function testGetCallbackFailure(Request $request)
 {
     $data = ['foo' => 'bar'];
     $viewHandler = new ViewHandler($this->router, $this->serializer, $this->templating, $this->requestStack, $this->exceptionWrapperHandler, ['jsonp' => false]);
     $jsonpHandler = new JsonpHandler('callback');
     $viewHandler->registerHandler('jsonp', [$jsonpHandler, 'createResponse']);
     $this->serializer->expects($this->once())->method('serialize')->will($this->returnValue(var_export($data, true)));
     $data = ['foo' => 'bar'];
     $view = new View($data);
     $view->setFormat('jsonp');
     $viewHandler->handle($view, $request);
 }
Example #11
0
 function it_sets_proper_values_for_non_html_requests(RequestConfiguration $requestConfiguration, RestViewHandler $restViewHandler, Response $response)
 {
     $requestConfiguration->isHtmlRequest()->willReturn(false);
     $view = View::create();
     $view->setSerializationContext(new SerializationContext());
     $requestConfiguration->getSerializationGroups()->willReturn(['Detailed']);
     $requestConfiguration->getSerializationVersion()->willReturn('2.0.0');
     $restViewHandler->setExclusionStrategyGroups(['Detailed'])->shouldBeCalled();
     $restViewHandler->setExclusionStrategyVersion('2.0.0')->shouldBeCalled();
     $restViewHandler->handle($view)->willReturn($response);
     $this->handle($requestConfiguration, $view)->shouldReturn($response);
 }
Example #12
0
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  * @dataProvider getCallbackFailureDataProvider
  */
 public function testGetCallbackFailure(Request $request)
 {
     $data = array('foo' => 'bar');
     $viewHandler = new ViewHandler(array('jsonp' => false));
     $jsonpHandler = new JsonpHandler('callback');
     $viewHandler->registerHandler('jsonp', array($jsonpHandler, 'createResponse'));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', array('get', 'getParameter'));
     $serializer = $this->getMock('stdClass', array('serialize', 'setVersion'));
     $serializer->expects($this->once())->method('serialize')->will($this->returnValue(var_export($data, true)));
     $container->expects($this->once())->method('get')->with('fos_rest.serializer')->will($this->returnValue($serializer));
     $container->expects($this->any())->method('getParameter')->will($this->onConsecutiveCalls('version', '1.0'));
     $viewHandler->setContainer($container);
     $data = array('foo' => 'bar');
     $view = new View($data);
     $view->setFormat('jsonp');
     $viewHandler->handle($view, $request);
 }
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  * @dataProvider getCallbackFailureDataProvider
  */
 public function testGetCallbackFailure(Request $request)
 {
     $data = ['foo' => 'bar'];
     $viewHandler = new ViewHandler(['jsonp' => false]);
     $jsonpHandler = new JsonpHandler('callback');
     $viewHandler->registerHandler('jsonp', [$jsonpHandler, 'createResponse']);
     $viewHandler->setSerializationContextAdapter($this->getMock(SerializationContextAdapterInterface::class));
     $container = $this->getMock(ContainerInterface::class);
     $serializer = $this->getMock('stdClass', ['serialize', 'setVersion']);
     $serializer->expects($this->once())->method('serialize')->will($this->returnValue(var_export($data, true)));
     $container->expects($this->any())->method('get')->with($this->equalTo('fos_rest.serializer'))->will($this->returnValue($serializer));
     $container->expects($this->any())->method('getParameter')->will($this->onConsecutiveCalls('version', '1.0'));
     $viewHandler->setContainer($container);
     $data = ['foo' => 'bar'];
     $view = new View($data);
     $view->setFormat('jsonp');
     $viewHandler->handle($view, $request);
 }
Example #14
0
 /**
  * trigger a action for given snippet specified over get-action parameter.
  *
  * @Post("/snippets/{uuid}")
  *
  * @param string $uuid
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function postTriggerAction($uuid, Request $request)
 {
     $view = null;
     $snippet = null;
     $this->initEnv($request);
     $action = $this->getRequestParameter($request, 'action', true);
     try {
         switch ($action) {
             case 'copy-locale':
                 $destLocale = $this->getRequestParameter($request, 'dest', true);
                 // call repository method
                 $snippet = $this->snippetRepository->copyLocale($uuid, $this->getUser()->getId(), $this->languageCode, explode(',', $destLocale));
                 break;
             default:
                 throw new RestException('Unrecognized action: ' . $action);
         }
         // prepare view
         $view = View::create($this->decorateSnippet($snippet->toArray(), $this->languageCode), $snippet !== null ? 200 : 204);
     } catch (RestException $exc) {
         $view = View::create($exc->toArray(), 400);
     }
     return $this->viewHandler->handle($view);
 }
Example #15
0
 /**
  * Return a JSON encoded scalar array of index names.
  *
  * @return JsonResponse
  */
 public function categoriesAction()
 {
     return $this->viewHandler->handle(View::create($this->searchManager->getCategoryNames()));
 }
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
  */
 public function testHandleNotSupported()
 {
     $viewHandler = new ViewHandler([]);
     $viewHandler->setSerializationContextAdapter($this->getMock('FOS\\RestBundle\\Context\\Adapter\\SerializationContextAdapterInterface'));
     $requestStack = new RequestStack();
     $requestStack->push(new Request());
     $container = $this->getMock(Container::class, ['get']);
     $container->expects($this->once())->method('get')->with('request_stack')->will($this->returnValue($requestStack));
     $viewHandler->setContainer($container);
     $data = ['foo' => 'bar'];
     $view = new View($data);
     $viewHandler->handle($view);
 }
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
  */
 public function testHandleNotSupported()
 {
     $viewHandler = new ViewHandler(array());
     $container = $this->getMock('\\Symfony\\Component\\DependencyInjection\\Container', array('get'));
     $container->expects($this->once())->method('get')->with('request')->will($this->returnValue(new Request()));
     $viewHandler->setContainer($container);
     $data = array('foo' => 'bar');
     $view = new View($data);
     $viewHandler->handle($view);
 }
Example #18
0
 private function handleView($document)
 {
     $view = View::create($document);
     $view->setSerializationContext(SerializationContext::create()->setSerializeNull(true));
     return $this->viewHandler->handle($view);
 }
Example #19
0
 /**
  * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
  */
 public function testHandleNotSupported()
 {
     $viewHandler = new ViewHandler([]);
     $viewHandler->setSerializationContextAdapter($this->getMock('FOS\\RestBundle\\Context\\Adapter\\SerializationContextAdapterInterface'));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', ['get']);
     $container->expects($this->once())->method('get')->with('request')->will($this->returnValue(new Request()));
     $viewHandler->setContainer($container);
     $data = ['foo' => 'bar'];
     $view = new View($data);
     $viewHandler->handle($view);
 }
 /**
  * @param View $view
  *
  * @return Response
  */
 protected function handle(View $view)
 {
     return $this->viewHandler->handle($view);
 }