当前位置: 首页>>代码示例>>PHP>>正文


PHP View::setFormat方法代码示例

本文整理汇总了PHP中FOS\RestBundle\View\View::setFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP View::setFormat方法的具体用法?PHP View::setFormat怎么用?PHP View::setFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FOS\RestBundle\View\View的用法示例。


在下文中一共展示了View::setFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSetFormat

 public function testSetFormat()
 {
     $view = new View();
     $format = 'bar';
     $view->setFormat($format);
     $this->assertEquals($format, $view->getFormat());
 }
开发者ID:hykz,项目名称:Depot,代码行数:7,代码来源:ViewTest.php

示例2: indexAction

 /**
  * @Route("/")
  */
 public function indexAction()
 {
     $view = new View();
     $view->setFormat('html');
     $view->setTemplate('TastdCoreBundle:Default:index.html.twig');
     return $view;
 }
开发者ID:oriodesign,项目名称:tastd-backend-demo,代码行数:10,代码来源:DefaultController.php

示例3: showAction

 public function showAction(Request $request, $exception, DebugLoggerInterface $logger = null)
 {
     $view = new View();
     $view->setData(json_decode($exception->getMessage(), true));
     $view->setFormat('json');
     return $this->container->get('fos_rest.view_handler')->handle($view);
 }
开发者ID:syedomair,项目名称:SymfonyAPIProject,代码行数:7,代码来源:CustomExceptionController.php

示例4: createView

 protected function createView($returnData)
 {
     $view = new View();
     $view->setData($returnData);
     $view->setStatusCode($returnData['status']);
     $view->setFormat('json');
     return $view;
 }
开发者ID:syedomair,项目名称:SymfonyAPIProject,代码行数:8,代码来源:BaseFOSRestController.php

示例5: editSeccionAction

 public function editSeccionAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $seccion = $em->getRepository('EtsiSiteBundle:Seccion')->find($id);
     $data = $this->getForm($seccion);
     $view = new View($data);
     $view->setTemplate('EtsiSiteBundle:Form:newSeccion.html.twig');
     $view->setFormat('html');
     return $this->get('fos_rest.view_handler')->handle($view);
 }
开发者ID:astrakel,项目名称:web,代码行数:10,代码来源:SeccionesController.php

示例6: editContenidoAction

 public function editContenidoAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $contenido = $em->getRepository('EtsiSiteBundle:Contenido')->find($id);
     $data = $this->getForm($contenido);
     $view = new View($data);
     $view->setTemplate('EtsiSiteBundle:Form:newContenido.html.twig');
     $view->setFormat('html');
     return $this->get('fos_rest.view_handler')->handle($view);
 }
开发者ID:astrakel,项目名称:web,代码行数:10,代码来源:ContenidosController.php

示例7: onKernelView

 /**
  * Renders the parameters and template and initializes a new response object with the
  * rendered content.
  *
  * @param GetResponseForControllerResultEvent $event A GetResponseForControllerResultEvent instance
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $configuration = $request->attributes->get('_view');
     $view = $event->getControllerResult();
     if (!$view instanceof View) {
         if (!$configuration && !$this->container->getParameter('fos_rest.view_response_listener.force_view')) {
             return parent::onKernelView($event);
         }
         $view = new View($view);
     }
     if ($configuration) {
         if ($configuration->getTemplateVar()) {
             $view->setTemplateVar($configuration->getTemplateVar());
         }
         if (null === $view->getStatusCode() && $configuration->getStatusCode()) {
             $view->setStatusCode($configuration->getStatusCode());
         }
         if ($configuration->getSerializerGroups()) {
             $context = $view->getSerializationContext() ?: new SerializationContext();
             $context->setGroups($configuration->getSerializerGroups());
             $view->setSerializationContext($context);
         }
     }
     if (null === $view->getFormat()) {
         $view->setFormat($request->getRequestFormat());
     }
     $vars = $request->attributes->get('_template_vars');
     if (!$vars) {
         $vars = $request->attributes->get('_template_default_vars');
     }
     $viewHandler = $this->container->get('fos_rest.view_handler');
     if ($viewHandler->isFormatTemplating($view->getFormat())) {
         if (!empty($vars)) {
             $parameters = (array) $viewHandler->prepareTemplateParameters($view);
             foreach ($vars as $var) {
                 if (!array_key_exists($var, $parameters)) {
                     $parameters[$var] = $request->attributes->get($var);
                 }
             }
             $view->setData($parameters);
         }
         $template = $request->attributes->get('_template');
         if ($template) {
             if ($template instanceof TemplateReference) {
                 $template->set('format', null);
             }
             $view->setTemplate($template);
         }
     }
     $response = $viewHandler->handle($view, $request);
     $event->setResponse($response);
 }
开发者ID:shreyans264,项目名称:symfonyPlayGround,代码行数:59,代码来源:ViewResponseListener.php

示例8: testGetCallbackFailure

 /**
  * @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);
 }
开发者ID:sblaut,项目名称:FOSRestBundle,代码行数:16,代码来源:JsonpHandlerTest.php

示例9: testGetCallbackFailure

 /**
  * @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);
 }
开发者ID:serialken,项目名称:BugTracker,代码行数:21,代码来源:JsonpHandlerTest.php

示例10: testGetCallbackFailure

 /**
  * @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);
 }
开发者ID:francescolaffi,项目名称:FOSRestBundle,代码行数:22,代码来源:JsonpHandlerTest.php

示例11: onKernelView

 /**
  * Renders the parameters and template and initializes a new response object with the
  * rendered content.
  *
  * @param GetResponseForControllerResultEvent $event A GetResponseForControllerResultEvent instance
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     $view = $event->getControllerResult();
     if (!$view instanceof View) {
         if (!$request->attributes->get('_view') && !$this->container->getParameter('fos_rest.view_response_listener.force_view')) {
             return;
         }
         $view = new View($view);
     }
     if (null === $view->getFormat()) {
         $view->setFormat($request->getRequestFormat());
     }
     $vars = $request->attributes->get('_template_vars');
     if (!$vars) {
         $vars = $request->attributes->get('_template_default_vars');
     }
     if (!empty($vars)) {
         $parameters = $view->getData();
         if (null !== $parameters && !is_array($parameters)) {
             throw new \RuntimeException('View data must be an array if using a templating aware format.');
         }
         $parameters = (array) $parameters;
         foreach ($vars as $var) {
             if (!array_key_exists($var, $parameters)) {
                 $parameters[$var] = $request->attributes->get($var);
             }
         }
         $view->setData($parameters);
     }
     $viewHandler = $this->container->get('fos_rest.view_handler');
     if ($viewHandler->isFormatTemplating($view->getFormat())) {
         $template = $request->attributes->get('_template');
         if ($template) {
             if ($template instanceof TemplateReference) {
                 $template->set('format', null);
                 $template->set('engine', null);
             }
             $view->setTemplate($template);
         }
     }
     $response = $viewHandler->handle($view, $request);
     $event->setResponse($response);
 }
开发者ID:richardmiller,项目名称:FOSRestBundle,代码行数:50,代码来源:ViewResponseListener.php

示例12: onKernelView

 /**
  * Renders the parameters and template and initializes a new response object with the
  * rendered content.
  *
  * @param GetResponseForControllerResultEvent $event
  */
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $request = $event->getRequest();
     /** @var \FOS\RestBundle\Controller\Annotations\View $configuration */
     $configuration = $request->attributes->get('_view');
     $view = $event->getControllerResult();
     $customViewDefined = true;
     if (!$view instanceof View) {
         if (!$configuration && !$this->container->getParameter('fos_rest.view_response_listener.force_view')) {
             return parent::onKernelView($event);
         }
         $view = new View($view);
         $customViewDefined = false;
     }
     if ($configuration) {
         if ($configuration->getTemplateVar()) {
             $view->setTemplateVar($configuration->getTemplateVar());
         }
         if ($configuration->getStatusCode() && (null === $view->getStatusCode() || Codes::HTTP_OK === $view->getStatusCode())) {
             $view->setStatusCode($configuration->getStatusCode());
         }
         if ($configuration->getSerializerGroups() && !$customViewDefined) {
             $context = $view->getSerializationContext() ?: new SerializationContext();
             $context->setGroups($configuration->getSerializerGroups());
             $view->setSerializationContext($context);
         }
         if ($configuration->getSerializerEnableMaxDepthChecks()) {
             $context = $view->getSerializationContext() ?: new SerializationContext();
             $context->enableMaxDepthChecks();
             $view->setSerializationContext($context);
         }
         $populateDefaultVars = $configuration->isPopulateDefaultVars();
     } else {
         $populateDefaultVars = true;
     }
     if (null === $view->getFormat()) {
         $view->setFormat($request->getRequestFormat());
     }
     $vars = $request->attributes->get('_template_vars');
     if (!$vars && $populateDefaultVars) {
         $vars = $request->attributes->get('_template_default_vars');
     }
     $viewHandler = $this->container->get('fos_rest.view_handler');
     if ($viewHandler->isFormatTemplating($view->getFormat())) {
         if (!empty($vars)) {
             $parameters = (array) $viewHandler->prepareTemplateParameters($view);
             foreach ($vars as $var) {
                 if (!array_key_exists($var, $parameters)) {
                     $parameters[$var] = $request->attributes->get($var);
                 }
             }
             $view->setData($parameters);
         }
         $template = $request->attributes->get('_template');
         if ($template) {
             if ($template instanceof TemplateReference) {
                 $template->set('format', null);
             }
             $view->setTemplate($template);
         }
     }
     $response = $viewHandler->handle($view, $request);
     $event->setResponse($response);
 }
开发者ID:juliettemijeon,项目名称:BDDProducts,代码行数:70,代码来源:ViewResponseListener.php

示例13: testPrepareTemplateParametersWithProvider

 /**
  * @dataProvider prepareTemplateParametersDataProvider
  */
 public function testPrepareTemplateParametersWithProvider($viewData, $templateData, $expected)
 {
     $handler = new ViewHandler(array('html' => true));
     $view = new View();
     $view->setFormat('html');
     $view->setData($viewData);
     if (null !== $templateData) {
         $view->setTemplateData($templateData);
     }
     $this->assertEquals($expected, $handler->prepareTemplateParameters($view));
 }
开发者ID:mgldev,项目名称:coffeetrack,代码行数:14,代码来源:ViewHandlerTest.php

示例14: testPrepareTemplateParametersWithProvider

 /**
  * @dataProvider prepareTemplateParametersDataProvider
  */
 public function testPrepareTemplateParametersWithProvider($viewData, $templateData, $expected)
 {
     $handler = $this->createViewHandler(['html' => true]);
     $handler->setSerializationContextAdapter($this->getMock('FOS\\RestBundle\\Context\\Adapter\\SerializationContextAdapterInterface'));
     $view = new View();
     $view->setFormat('html');
     $view->setData($viewData);
     if (null !== $templateData) {
         $view->setTemplateData($templateData);
     }
     $this->assertEquals($expected, $handler->prepareTemplateParameters($view));
 }
开发者ID:fsevestre,项目名称:FOSRestBundle,代码行数:15,代码来源:ViewHandlerTest.php

示例15: jsonpAction

 public function jsonpAction()
 {
     $data = array('foo' => 'bar');
     $view = new View($data);
     $view->setFormat('jsonp');
     return $this->viewHandler->handle($view);
 }
开发者ID:nashidgit,项目名称:LiipHelloBundle,代码行数:7,代码来源:HelloController.php


注:本文中的FOS\RestBundle\View\View::setFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。