本文整理汇总了PHP中FOS\RestBundle\View\View::getRoute方法的典型用法代码示例。如果您正苦于以下问题:PHP View::getRoute方法的具体用法?PHP View::getRoute怎么用?PHP View::getRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FOS\RestBundle\View\View
的用法示例。
在下文中一共展示了View::getRoute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetRoute
public function testSetRoute()
{
$routeName = 'users';
$view = View::createRouteRedirect($routeName, array(), Codes::HTTP_CREATED);
$this->assertAttributeEquals($routeName, 'route', $view);
$this->assertAttributeEquals(null, 'location', $view);
$this->assertEquals(Codes::HTTP_CREATED, $view->getResponse()->getStatusCode());
$view->setLocation($routeName);
$this->assertAttributeEquals($routeName, 'location', $view);
$this->assertAttributeEquals(null, 'route', $view);
$view = new View();
$route = 'route';
$view->setRoute($route);
$this->assertEquals($route, $view->getRoute());
}
示例2: createResponse
/**
* Handles creation of a Response using either redirection or the templating/serializer service.
*
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*/
public function createResponse(View $view, Request $request, $format)
{
$route = $view->getRoute();
$location = $route ? $this->urlGenerator->generate($route, (array) $view->getRouteParameters(), UrlGeneratorInterface::ABSOLUTE_URL) : $view->getLocation();
if ($location) {
return $this->createRedirectResponse($view, $location, $format);
}
$response = $this->initResponse($view, $format);
if (!$response->headers->has('Content-Type')) {
$response->headers->set('Content-Type', $request->getMimeType($format));
}
return $response;
}
示例3: createResponse
/**
* Handles creation of a Response using either redirection or the templating/serializer service
*
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*/
public function createResponse(View $view, Request $request, $format)
{
$headers = $view->getHeaders();
if (empty($headers['Content-Type'])) {
$view->setHeader('Content-Type', $request->getMimeType($format));
}
$route = $view->getRoute();
$location = $route ? $this->getRouter()->generate($route, (array) $view->getData(), true) : $view->getLocation();
if ($location) {
return $this->createRedirectResponse($view, $location, $format);
}
if ($this->isFormatTemplating($format)) {
$content = $this->renderTemplate($view, $format);
} else {
$serializer = $this->getSerializer($view);
$content = $serializer->serialize($view->getData(), $format);
}
return new Response($content, $this->getStatusCode($view), $view->getHeaders());
}
示例4: createResponse
/**
* Handles creation of a Response using either redirection or the templating/serializer service
*
* @param View $view
* @param Request $request
* @param string $format
*
* @return Response
*/
public function createResponse(View $view, Request $request, $format)
{
$route = $view->getRoute();
$location = $route ? $this->getRouter()->generate($route, (array) $view->getData(), true) : $view->getLocation();
if ($location) {
return $this->createRedirectResponse($view, $location, $format);
}
$content = null;
if ($this->isFormatTemplating($format)) {
$content = $this->renderTemplate($view, $format);
} elseif ($this->serializeNull || null !== $view->getData()) {
$serializer = $this->getSerializer($view);
if ($serializer instanceof Serializer) {
$context = $this->getSerializationContext($view);
$content = $serializer->serialize($view->getData(), $format, $context);
} else {
$content = $serializer->serialize($view->getData(), $format);
}
}
$response = $view->getResponse();
$response->setStatusCode($this->getStatusCode($view, $content));
if (null !== $content) {
$response->setContent($content);
}
if (!$response->headers->has('Content-Type')) {
$response->headers->set('Content-Type', $request->getMimeType($format));
}
return $response;
}
示例5: 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();
if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
return false;
}
/** @var \FOS\RestBundle\Controller\Annotations\View $configuration */
$configuration = $request->attributes->get('_view');
$view = $event->getControllerResult();
$customViewDefined = true;
if (!$view instanceof View) {
if (!$configuration && !$this->forceView) {
return;
}
$view = new View($view);
$customViewDefined = false;
}
if ($configuration) {
if ($configuration->getTemplateVar()) {
$view->setTemplateVar($configuration->getTemplateVar());
}
if ($configuration->getStatusCode() && (null === $view->getStatusCode() || Response::HTTP_OK === $view->getStatusCode())) {
$view->setStatusCode($configuration->getStatusCode());
}
$context = $view->getContext();
if ($configuration->getSerializerGroups() && !$customViewDefined) {
$context->addGroups($configuration->getSerializerGroups());
}
if ($configuration->getSerializerEnableMaxDepthChecks()) {
$context->setMaxDepth(0);
}
$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');
}
if ($this->viewHandler->isFormatTemplating($view->getFormat()) && !$view->getRoute() && !$view->getLocation()) {
if (!empty($vars)) {
$parameters = (array) $this->viewHandler->prepareTemplateParameters($view);
foreach ($vars as $var) {
if (!array_key_exists($var, $parameters)) {
$parameters[$var] = $request->attributes->get($var);
}
}
$view->setData($parameters);
}
$template = null !== $configuration && $configuration->getTemplate() ? $configuration->getTemplate() : $request->attributes->get('_template');
if ($template && !$view->getTemplate()) {
if ($template instanceof TemplateReferenceInterface) {
$template->set('format', null);
}
$view->setTemplate($template);
}
}
$response = $this->viewHandler->handle($view, $request);
$event->setResponse($response);
}