本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\FilterResponseEvent::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP FilterResponseEvent::getRequest方法的具体用法?PHP FilterResponseEvent::getRequest怎么用?PHP FilterResponseEvent::getRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\FilterResponseEvent
的用法示例。
在下文中一共展示了FilterResponseEvent::getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelResponse
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
if (null !== $response && $response instanceof PluginResponseInterface) {
//when a route from a plugin is hit
if (!$event->getRequest()->attributes->get('_jarves_is_plugin')) {
//we accept only plugin routes.
return;
}
$pageResponse = $this->pageStack->getPageResponse();
/** @var $content Content */
$content = $event->getRequest()->attributes->get('_content');
//this is later used in ContentTypes\TypePlugin, so it won't execute
//the same plugin again.
$pageResponse->setPluginResponse($content->getId(), $response);
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
//when this was a master request, we need to render the actual content of the page,
//so HttpKernel can return a valid ready rendered response
//if a plugin route has been successfully requested
//we need to handle also the Jarves editor
if ($this->editMode->isEditMode()) {
$this->editMode->registerEditor();
}
$pageResponse->renderContent();
}
//maintain the actual PageResponse
$event->setResponse($pageResponse);
}
}
示例2: onKernelResponse
public function onKernelResponse(FilterResponseEvent $event)
{
$controller = $event->getRequest()->attributes->get('_controller');
if (empty($controller)) {
return;
}
if (strpos($controller, '::') !== false) {
$controller = explode('::', $controller, 2);
$class = new \ReflectionClass($controller[0]);
$method = $class->getMethod($controller[1]);
$annotation = $this->reader->getMethodAnnotation($method, 'PSX\\PSXBundle\\Configuration\\Outgoing');
$response = $event->getResponse();
$writer = $this->getWriter($event->getRequest());
if ($response instanceof DataResponse) {
if ($annotation instanceof Outgoing) {
$file = $this->rootDir . '/' . $annotation->getFile();
$data = $this->assimilator->assimilate(JsonSchema::fromFile($file), $response->getData());
$response->headers->set('Content-Type', $writer->getContentType());
$response->setContent($writer->write($data));
} else {
$data = $this->normalizeData($response->getData());
$response->headers->set('Content-Type', $writer->getContentType());
$response->setContent($writer->write($data));
}
} else {
throw new RuntimeException('Can only transform responses of PSX\\PSXBundle\\DataResponse');
}
}
}
示例3: onResponseLoad
/**
* @param FilterResponseEvent $event
*/
public function onResponseLoad(FilterResponseEvent $event)
{
if (!$event->getRequest()->attributes->has('AJAX_PROCESSING')) {
return;
}
$event->setResponse(new Response($this->adapter->getResponse($event->getRequest()->attributes->get('ajax_commands'))));
}
示例4: onRespond
/**
* Redirects login attempts on already-logged-in session to the destination.
*/
public function onRespond(FilterResponseEvent $event)
{
// Return early in most cases.
if ($event->getRequest()->getMethod() !== 'POST') {
return;
}
if (!$this->currentUser->isAuthenticated()) {
return;
}
if (!$event->isMasterRequest()) {
return;
}
if (!$event->getRequest()->query->has('destination')) {
return;
}
if ($event->getResponse() instanceof RedirectResponse) {
return;
}
// There has to be a better way to figure out if we landed on the 403/404 page.
$page_403 = $this->configFactory->get('system.site')->get('page.403');
$page_404 = $this->configFactory->get('system.site')->get('page.404');
$path = $this->currentPath->getPath();
$route = $this->currentRouteMatch->getRouteName();
if ($route == 'system.403' || $page_403 && $path == $page_403 || $route == 'system.404' || $page_404 && $path == $page_404) {
// RedirectResponseSubscriber will convert to absolute URL for us.
$event->setResponse(new RedirectResponse($this->redirectDestination->get(), RedirectResponse::HTTP_SEE_OTHER));
}
}
示例5: onKernelResponse
/**
* Handles the onKernelResponse event.
*
* @param FilterResponseEvent $event A FilterResponseEvent instance
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$master = HttpKernelInterface::MASTER_REQUEST === $event->getRequestType();
if ($this->onlyMasterRequests && !$master) {
return;
}
if ($this->onlyException && null === $this->exception) {
return;
}
$exception = $this->exception;
$this->exception = null;
if (null !== $this->matcher && !$this->matcher->matches($event->getRequest())) {
return;
}
if ($profile = $this->profiler->collect($event->getRequest(), $event->getResponse(), $exception)) {
if ($master) {
$this->profiler->saveProfile($profile);
foreach ($this->children as $child) {
$child->setParent($profile);
$this->profiler->saveProfile($child);
}
$this->children = array();
} else {
$this->children[] = $profile;
}
}
}
示例6: onKernelResponse
/**
* 输出debugBar,只有当页面有</body>标签时有效。
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$request = $event->getRequest();
if (!$event->isMasterRequest()) {
return;
}
if ($request->isXmlHttpRequest()) {
return;
}
if ($response->isRedirection() || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat()) {
return;
}
$path = null;
if ($this->app['debug_bar.auto_res']) {
$scriptName = $event->getRequest()->server->get('SCRIPT_NAME');
$path = $scriptName . $this->app['debug_bar.path'];
} else {
$path = $this->app['debug_bar.path'];
}
$render = $this->app['debug_bar']->getJavascriptRenderer($path);
ob_start();
echo $render->renderHead();
echo $render->render();
$debugContent = ob_get_contents();
ob_end_clean();
$content = $response->getContent();
if (false === strpos($content, '</body>')) {
$content .= $debugContent;
} else {
$content = str_replace("</body>", $debugContent . '</body>', $content);
}
$event->getResponse()->setContent($content);
}
示例7: onKernelResponse
/**
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$allowedMethods = $this->loader->getAllowedMethods();
if (isset($allowedMethods[$event->getRequest()->get('_route')])) {
$event->getResponse()->headers->set('Allow', implode(', ', $allowedMethods[$event->getRequest()->get('_route')]));
}
}
示例8: replaceMarkup
/**
* Parses content of response and set the replaced html as new content.
*
* @param FilterResponseEvent $event
*/
public function replaceMarkup(FilterResponseEvent $event)
{
$format = $event->getRequest()->getRequestFormat(null);
if (!array_key_exists($format, $this->markupParser)) {
return;
}
$response = $event->getResponse();
$response->setContent($this->markupParser[$format]->parse($response->getContent(), $event->getRequest()->getLocale()));
}
示例9: onKernelResponse
/**
* kernel.responseイベント
*/
public function onKernelResponse(FilterResponseEvent $event)
{
// kernel.responseイベント発生時に出力フォーマットを判定し、
// csvであればContent-Dispositionヘッダを追加、かつ、レスポンスボディをSJIS-winに変換する
if ($event->getRequest()->getRequestFormat() === 'csv') {
$response = $event->getResponse();
$response->setContent(mb_convert_encoding($response->getContent(), 'SJIS-win', mb_internal_encoding()));
$response->headers->set('Content-Disposition', sprintf('attachment; filename=%s.csv', $event->getRequest()->get('_filename')));
}
}
示例10: isEnabled
/**
* Check if snippets are allowed for this request.
*
* @param FilterResponseEvent $event
*/
protected function isEnabled(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return false;
}
if (Zone::isFrontend($event->getRequest())) {
return true;
}
return $event->getRequest()->attributes->get('allow_snippets', false);
}
示例11: onKernelResponse
/**
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
return;
}
$allowedMethods = $this->loader->getAllowedMethods();
if (isset($allowedMethods[$event->getRequest()->get('_route')])) {
$event->getResponse()->headers->set('Allow', implode(', ', $allowedMethods[$event->getRequest()->get('_route')]));
}
}
示例12: addRobotTags
/**
* Add resolved tags to X-Robots-Tag response header.
*
* @param FilterResponseEvent $event
*/
public function addRobotTags(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
if ($this->cloak && !$this->requestChecker->isCrawler($event->getRequest())) {
return;
}
if ($tags = $this->tagResolver->resolve($event->getRequest())) {
$event->getResponse()->headers->set('X-Robots-Tag', implode(', ', $tags));
}
}
示例13: onKernelResponse
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$request = $event->getRequest();
// exclude render tags in the WDT and Profiler
$controller = $request->attributes->get('_controller');
if ($controller && 'WebProfilerBundle' === substr($controller, 0, 17)) {
return;
}
// do not highlight master responses that are not HTML based
$contentType = $response->headers->get('Content-Type');
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType() && $contentType && !preg_match('{^(text/html|application/xhtml+xml)\\b}', $contentType)) {
return;
}
// skip non-cacheable responses
if (!$response->isCacheable()) {
return;
}
$response->setContent(sprintf('
<div class="esi-debug">
<div class="esi-debug-details">
ESI: %s, Rendered: %s, Cache-Control: %s
</div>
%s
</div>
<style>
.esi-debug {
border: 1px solid red;
}
.esi-debug-details {
background: red;
position: absolute;
color: white;
}
.esi-debug:hover {
background: rgba(255, 0, 0, .25);
border-color #CC0000;
cursor: pointer;
}
.esi-debug:hover .esi-debug-details {
background: #CC0000;
z-index: 9999;
}
</style>
', $event->getRequest()->getRequestUri(), date('Y-m-d H:i:s'), $response->headers->get('cache-control'), $response->getContent()));
}
示例14: onResponse
/**
* This method is executed on kernel.response event
*
* @param FilterResponseEvent $event
*
* @see {http://symfony.com/doc/current/components/http_kernel/introduction.html#the-kernel-response-event}
*/
public function onResponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
if ($request->attributes->get('response_source') === 'cache') {
//Prevents re-caching response from cache
$event->stopPropagation();
return;
}
if (!$event->isMasterRequest()) {
return;
//Caching should only occur on master requests, see https://github.com/kiler129/SupercacheBundle/issues/10
}
$this->responseHandler->cacheResponse($event->getRequest(), $event->getResponse());
}
示例15: onKernelResponse
public function onKernelResponse(FilterResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
// don't do anything if it's not the master request
return;
}
if (false === strpos($event->getRequest()->getRequestUri(), 'login')) {
if ($event->getRequest()->isXmlHttpRequest() && $event->getResponse()->getStatusCode() == "302") {
$event->getResponse()->setStatusCode(401);
$response = new \Symfony\Component\HttpFoundation\Response();
$response->setStatusCode(401);
$event->setResponse($response);
}
}
}