本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent::setControllerResult方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseForControllerResultEvent::setControllerResult方法的具体用法?PHP GetResponseForControllerResultEvent::setControllerResult怎么用?PHP GetResponseForControllerResultEvent::setControllerResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent
的用法示例。
在下文中一共展示了GetResponseForControllerResultEvent::setControllerResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serializeRawData
/**
* Tries to serialize data that are not API resources (e.g. the entrypoint or data returned by a custom controller).
*
* @param GetResponseForControllerResultEvent $event
* @param Request $request
* @param object $controllerResult
*
* @throws RuntimeException
*/
private function serializeRawData(GetResponseForControllerResultEvent $event, Request $request, $controllerResult)
{
if (!$request->attributes->get('_api_respond')) {
return;
}
if (is_object($controllerResult)) {
$event->setControllerResult($this->serializer->serialize($controllerResult, $request->getRequestFormat()));
return;
}
if (!$this->serializer instanceof EncoderInterface) {
throw new RuntimeException(sprintf('The serializer instance must implements the "%s" interface.', EncoderInterface::class));
}
$event->setControllerResult($this->serializer->encode($controllerResult, $request->getRequestFormat()));
}
示例2: decorateView
/**
* @param GetResponseForControllerResultEvent $event
*/
protected function decorateView(GetResponseForControllerResultEvent $event)
{
$params = $event->getRequest()->attributes;
array_walk($this->decorators, function (DecoratorInterface $decorator) use($event, $params) {
$event->setControllerResult($decorator->decorate($params, $event->getControllerResult()));
});
}
示例3: onKernelView
/**
* Persists, updates or delete data return by the controller if applicable.
*
* @param GetResponseForControllerResultEvent $event
*
* @return mixed
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
if (!in_array($request->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_DELETE])) {
return;
}
$resourceType = $request->attributes->get('_resource_type');
if (!$resourceType) {
return;
}
$controllerResult = $event->getControllerResult();
if (null === ($objectManager = $this->getManager($resourceType, $controllerResult))) {
return $controllerResult;
}
switch ($request->getMethod()) {
case Request::METHOD_POST:
$objectManager->persist($controllerResult);
break;
case Request::METHOD_DELETE:
$objectManager->remove($controllerResult);
$event->setControllerResult(null);
break;
}
$objectManager->flush();
}
示例4: onKernelView
/**
* Persists, updates or delete data return by the controller if applicable.
*
* @param GetResponseForControllerResultEvent $event
*
* @return mixed
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$request = $event->getRequest();
if ($request->isMethodSafe()) {
return;
}
$resourceClass = $request->attributes->get('_api_resource_class');
if (null === $resourceClass) {
return;
}
$controllerResult = $event->getControllerResult();
if (null === ($objectManager = $this->getManager($resourceClass, $controllerResult))) {
return;
}
switch ($request->getMethod()) {
case Request::METHOD_POST:
$objectManager->persist($controllerResult);
break;
case Request::METHOD_DELETE:
$objectManager->remove($controllerResult);
$event->setControllerResult(null);
break;
}
$objectManager->flush();
}
示例5: onHtmlFragment
/**
* Converts an HtmlFragment into an HtmlPage.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event
* The Event to process.
*/
public function onHtmlFragment(GetResponseForControllerResultEvent $event)
{
$fragment = $event->getControllerResult();
if ($fragment instanceof HtmlFragment && !$fragment instanceof HtmlPage) {
$page = $this->fragmentRenderer->render($fragment);
$event->setControllerResult($page);
}
}
示例6: onKernelView
/**
* Handles Kernel View events
*
* @param GetResponseForControllerResultEvent $event
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
$parameters = $event->getControllerResult();
if (!$response instanceof Response && ($template = $request->attributes->get('_template'))) {
return $event->setControllerResult($this->templating->render($template, $parameters));
}
}
示例7: onKernelView
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$result = $event->getControllerResult();
if (!$result instanceof SuccessResult) {
return;
}
$metadata = $result->getMetadata();
$response = empty($metadata) ? new Response('', 204) : new JsonResponse($metadata, 200);
$event->setControllerResult($response);
}
示例8: onKernelView
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$result = $event->getControllerResult();
$request = $event->getRequest();
if (!$result instanceof ResourceCreatedResult) {
return;
}
$transformerKey = $request->attributes->get('_rest[transform]', null, true);
$transformedData = $this->transformer->transform($transformerKey, $result->getResource());
$transformedData = $this->setMetadata($transformedData, $result);
$event->setControllerResult(new JsonResponse($transformedData, 201));
}
示例9: onKernelView
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$request = $event->getRequest();
if (!$request->attributes->has('_rest') || $event->getControllerResult() instanceof Response) {
return;
}
$config = $this->normalizeConfig($request->attributes->get('_rest', array(), true));
$includes = $request->query->get('include', null);
$data = $event->getControllerResult();
$transformedData = $this->transformResult($config, $data, $includes, $request);
$event->setControllerResult($transformedData);
}
示例10: onKernelView
/**
* @param GetResponseForControllerResultEvent $event
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$_route = $event->getRequest()->attributes->get('_route');
if ('oro_shortcut_actionslist' == $_route) {
$controllerResult = $event->getControllerResult();
foreach ($controllerResult['actionsList'] as $route => $data) {
if (!$this->whitelistProvider->isItemWhitelisted($route)) {
unset($controllerResult['actionsList'][$route]);
}
}
$event->setControllerResult($controllerResult);
}
}
示例11: __invoke
public function __invoke(GetResponseForControllerResultEvent $event)
{
$controllerResult = $event->getControllerResult();
$callback = $this->app['callback_resolver']->resolveCallback($this->callback);
if (!$this->shouldRun($callback, $controllerResult)) {
return;
}
$response = call_user_func($callback, $controllerResult, $event->getRequest());
if ($response instanceof Response) {
$event->setResponse($response);
} elseif (null !== $response) {
$event->setControllerResult($response);
}
}
示例12: onKernelView
/**
* @param GetResponseForControllerResultEvent $event
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$_route = $event->getRequest()->attributes->get('_route');
if ('oro_config_configuration_system' !== $_route) {
return;
}
$result = $event->getControllerResult();
/** @var AbstractNodeDefinition $data */
$data = clone $result['data'];
$this->cleanTree($data);
$form = clone $result['form'];
$this->clearForm($form);
$result['data'] = $data;
$result['form'] = $form;
$event->setControllerResult($result);
}
示例13: onKernelView
/**
* Persists, updates or delete data return by the controller if applicable.
*
* @param GetResponseForControllerResultEvent $event
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$user = $event->getControllerResult();
if (!$user instanceof UserInterface) {
return;
}
switch ($event->getRequest()->getMethod()) {
case Request::METHOD_POST:
case Request::METHOD_PUT:
$this->userManager->updateUser($user, false);
break;
case Request::METHOD_DELETE:
$this->userManager->deleteUser($user);
$event->setControllerResult(null);
break;
}
}
示例14: onKernelView
/**
* @param GetResponseForControllerResultEvent $event
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$response = $event->getControllerResult();
if ($response instanceof Response) {
// If it's a response, just continue
return;
}
$request = $event->getRequest();
if ($request->attributes->has('_template')) {
//template is already set
return;
}
$nodeTranslation = $request->attributes->get('_nodeTranslation');
if ($nodeTranslation) {
$entity = $request->attributes->get('_entity');
$url = $request->attributes->get('url');
$nodeMenu = $request->attributes->get('_nodeMenu');
$parameters = $request->attributes->get('_renderContext');
if ($request->get('preview') === true) {
$version = $request->get('version');
if (!empty($version) && is_numeric($version)) {
$nodeVersion = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')->find($version);
if (!is_null($nodeVersion)) {
$entity = $nodeVersion->getRef($this->em);
}
}
}
$renderContext = array('nodetranslation' => $nodeTranslation, 'slug' => $url, 'page' => $entity, 'resource' => $entity, 'nodemenu' => $nodeMenu);
if (is_array($parameters) || $parameters instanceof \ArrayObject) {
$parameters = array_merge($renderContext, (array) $parameters);
} else {
$parameters = $renderContext;
}
if (is_array($response)) {
// If the response is an array, merge with rendercontext
$parameters = array_merge($parameters, $response);
}
//set the rendercontext with all params as response, plus the template in the request attribs
//the SensioFrameworkExtraBundle kernel.view will handle everything else
$event->setControllerResult((array) $parameters);
$template = new Template(array());
$template->setTemplate($entity->getDefaultView());
$request->attributes->set('_template', $template);
}
}
示例15: onKernelView
/**
* Persists, updates or delete data return by the controller if applicable.
*
* @param GetResponseForControllerResultEvent $event
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$request = $event->getRequest();
try {
RequestAttributesExtractor::extractAttributes($request);
} catch (RuntimeException $e) {
return;
}
$user = $event->getControllerResult();
if (!$user instanceof UserInterface || $request->isMethodSafe(false)) {
return;
}
switch ($request->getMethod()) {
case Request::METHOD_DELETE:
$this->userManager->deleteUser($user);
$event->setControllerResult(null);
break;
default:
$this->userManager->updateUser($user);
break;
}
}