本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\FilterResponseEvent类的典型用法代码示例。如果您正苦于以下问题:PHP FilterResponseEvent类的具体用法?PHP FilterResponseEvent怎么用?PHP FilterResponseEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FilterResponseEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onResponse
/**
* Checking request and response and decide whether we need a redirect
*
* @param FilterResponseEvent $event
*/
public function onResponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if ($request->get(self::HASH_NAVIGATION_HEADER) || $request->headers->get(self::HASH_NAVIGATION_HEADER)) {
$location = '';
$isFullRedirect = false;
if ($response->isRedirect()) {
$location = $response->headers->get('location');
if ($request->attributes->get('_fullRedirect') || !is_object($this->security->getToken())) {
$isFullRedirect = true;
}
}
if ($response->isNotFound() || $response->getStatusCode() == 503 && !$this->isDebug) {
$location = $request->getUri();
$isFullRedirect = true;
}
if ($location) {
$response = $this->templating->renderResponse('OroNavigationBundle:HashNav:redirect.html.twig', array('full_redirect' => $isFullRedirect, 'location' => $location));
}
// disable cache for ajax navigation pages and change content type to json
$response->headers->set('Content-Type', 'application/json');
$response->headers->addCacheControlDirective('no-cache', true);
$response->headers->addCacheControlDirective('max-age', 0);
$response->headers->addCacheControlDirective('must-revalidate', true);
$response->headers->addCacheControlDirective('no-store', true);
$event->setResponse($response);
}
}
示例2: onCoreResponse
public function onCoreResponse(FilterResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
$response = $event->getResponse();
$request = $event->getRequest();
// do not capture redirects or modify XML HTTP Requests
if ($request->isXmlHttpRequest()) {
return;
}
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
if (null !== $session = $request->getSession()) {
// keep current flashes for one more request
$session->setFlashes($session->getFlashes());
}
$response->setContent($this->templating->render('WebProfilerBundle:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location'))));
$response->setStatusCode(200);
$response->headers->remove('Location');
}
if (!$response->headers->has('X-Debug-Token')
|| '3' === substr($response->getStatusCode(), 0, 1)
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
|| 'html' !== $request->getRequestFormat()
) {
return;
}
$this->injectToolbar($response);
}
示例3: doResponse
public function doResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$url = $event->getRequest()->getPathInfo();
$prefix = ConfigQuery::read("back_office_path");
$defaultEnabled = intval(ConfigQuery::read("back_office_path_default_enabled", "1"));
$contentType = $response->headers->get('Content-Type');
// skip if the default thelia prefixe is enabled
if ($defaultEnabled === 1) {
return;
}
$isValid = strpos($url, '/' . BackOfficePath::DEFAULT_THELIA_PREFIX) === 0 && $prefix !== null && $prefix !== "";
if ($isValid) {
if ($response instanceof RedirectResponse) {
$targetUrl = $response->getTargetUrl();
if (strpos($targetUrl, '/' . BackOfficePath::DEFAULT_THELIA_PREFIX) !== false) {
$newUrl = $this->replaceUrl($targetUrl, BackOfficePath::DEFAULT_THELIA_PREFIX, $prefix);
$response->setTargetUrl($newUrl);
}
} else {
$content = $this->replaceUrl($response->getContent(), BackOfficePath::DEFAULT_THELIA_PREFIX, $prefix);
$response->setContent($content);
}
}
}
示例4: saveBasket
public function saveBasket(Event\FilterResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return false;
}
$order = $this->get('basket.order');
$cookieName = $this->get('cfg')->basket->cookieName;
$token = $this->get('request')->cookies->get($cookieName);
// Skip if the order is empty
if (count($order->items) < 1) {
// If the cookie was in the request, delete it and clear the cookie
if ($token) {
$this->deleteBasket();
$this->get('http.cookies')->add(new Cookie($cookieName, null, new \DateTime('-1 hour')));
}
return false;
}
// See if a basket already exists.
$basket = $this->_services['order.basket.loader']->getByToken($token);
// Update with current order details.
if ($basket) {
$basketID = $basket->basket_id;
$this->_services['order.basket.edit']->update($basketID, $order);
} else {
// Create a new basket
$basketID = $this->_services['order.basket.create']->create($order);
$basket = $this->_services['order.basket.loader']->getByID($basketID);
}
// Create the cookie
$token = $this->_services['order.basket.token']->generate($basketID, $basket->created_at);
$cookieName = $this->_services['cfg']->basket->cookieName;
$expire = new \DateTime('+' . $this->_services['cfg']->basket->cookieLength);
$cookie = new Cookie($cookieName, $token, $expire);
$this->_services['http.cookies']->add($cookie);
}
示例5: onKernelResponse
/**
* Unwraps an enforced response.
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
if ($response instanceof EnforcedResponse && $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
$event->setResponse($response->getResponse());
}
}
示例6: onKernelResponse
/**
* Filters the Response.
*
* @param FilterResponseEvent $event A FilterResponseEvent instance
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if ('HEAD' === $request->getMethod()) {
// cf. RFC2616 14.13
$length = $response->headers->get('Content-Length');
$response->setContent('');
if ($length) {
$response->headers->set('Content-Length', $length);
}
}
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
if (null === $response->getCharset()) {
$response->setCharset($this->charset);
}
if ($response->headers->has('Content-Type')) {
return;
}
$format = $request->getRequestFormat();
if (null !== $format && ($mimeType = $request->getMimeType($format))) {
$response->headers->set('Content-Type', $mimeType);
}
}
示例7: onKernelResponse
/**
* Logs master response on event KernelEvents::RESPONSE.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->logResponse($event->getResponse());
}
示例8: processCount
public function processCount(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$connecte = new Connecte();
$ip = $this->container->get('request')->getClientIp();
$times = time();
$doctrine = $this->container->get('doctrine.orm.entity_manager');
$listIp = $this->doctrine->getRepository('SNSysNewsBundle:Connecte')->findAll();
if (!in_array($ip, $listIp)) {
$connecte->setIp($ip);
$connecte->setTimes($times);
$doctrine->persist($connecte);
$doctrine->flush();
} else {
$times = time();
$connecte->setTimes($times);
$doctrine->persist($connecte);
$doctrine->flush();
}
$time_5 = time() - 60 * 5;
if ($times < $time_5) {
$connecte = $this->doctrine->getRepository('SNSysNewsBundle:Connecte')->findOneByTimes($times);
$doctrine->remove($connecte);
$doctrine->flush();
}
$nbvisit = $doctrine->getRepository('SNSysNewsBundle:Connecte')->getcountnumbervisit();
$rep = $this->counthtml->viewNbVisit($event->getResponse(), $nbvisit);
$event->setResponse($rep);
}
示例9: onResponse
/**
* Renders the ajax commands right before preparing the result.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The response event, which contains the possible AjaxResponse object.
*/
public function onResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
if ($response instanceof AjaxResponse) {
$response->prepareResponse($event->getRequest());
}
}
示例10: onKernelResponse
/**
* Adds the Contao headers to the Symfony response.
*
* @param FilterResponseEvent $event The event object
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$this->contaoFramework->isInitialized()) {
return;
}
$event->setResponse($this->mergeHttpHeaders($event->getResponse()));
}
示例11: onKernelResponse
public function onKernelResponse(FilterResponseEvent $e)
{
if (!$this->isRestRoute($e->getRequest())) {
return;
}
$e->getDispatcher()->dispatch('sdispatcher.rest_response', $e);
}
示例12: onKernelResponse
public function onKernelResponse(FilterResponseEvent $event)
{
if ($this->url || !$event->isMasterRequest() || !\sfContext::hasInstance()) {
return;
}
$response_headers = $event->getResponse()->headers;
if ($response_headers->has('x-debug-token-link') && strpos(\sfContext::getInstance()->getResponse()->getContentType(), 'javascript') === false && !$event->getRequest()->isXmlHttpRequest()) {
$this->url = $response_headers->get('x-debug-token-link');
$link = json_encode($response_headers->get('x-debug-token-link'));
echo <<<JAVASCRIPT
<script>
(function() {
var bar_node = document.getElementById('sfWebDebugDetails'), link_node, li_node;
if(bar_node) { // We have a debug bar
link_node = document.createElement('a');
link_node.href = {$link};
link_node.appendChild(document.createTextNode('Symfony 2'));
li_node = document.createElement('li');
li_node.appendChild(link_node);
bar_node.insertBefore(li_node,bar_node.firstChild);
}
}())
</script>
JAVASCRIPT;
}
}
示例13: onResponse
/**
* Process onReslonse event, updates user history information
*
* @param FilterResponseEvent $event
* @return bool|void
*/
public function onResponse(FilterResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
// Do not do anything
return;
}
$request = $event->getRequest();
$response = $event->getResponse();
// do not process requests other than in html format
// with 200 OK status using GET method and not _internal and _wdt
if (!$this->matchRequest($response, $request)) {
return false;
}
$postArray = ['url' => $request->getRequestUri(), 'user' => $this->user];
/** @var $historyItem NavigationHistoryItem */
$historyItem = $this->em->getRepository('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationHistoryItem')->findOneBy($postArray);
if (!$historyItem) {
/** @var $historyItem \Oro\Bundle\NavigationBundle\Entity\NavigationItemInterface */
$historyItem = $this->navItemFactory->createItem(NavigationHistoryItem::NAVIGATION_HISTORY_ITEM_TYPE, $postArray);
}
$historyItem->setTitle($this->titleService->getSerialized());
// force update
$historyItem->doUpdate();
$this->em->persist($historyItem);
$this->em->flush($historyItem);
return true;
}
示例14: onResponse
/**
* Trigger event for RESPONSE Kervenel vent
*
* @param FilterResponseEvent $event event
*/
public function onResponse(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;
}
$http = $request->isSecure() ? 'https' : 'http';
if (empty($this->extensions)) {
return;
}
if (count($this->extensions) == 0) {
return;
}
$extensions = implode('|', $this->extensions);
$content = $response->getContent();
$pattern = '/="[^"]*\\/(css|js|var|bundles)\\/(.*)\\.(' . $extensions . ')([^"]*)"/i';
$replace = '="' . $http . '://' . $this->domain . '/${1}/${2}.${3}${4}"';
$content = preg_replace($pattern, $replace, $content);
$response->setContent($content);
}
示例15: onKernelResponse
/**
* Filters the Response.
*
* @param FilterResponseEvent $event A FilterResponseEvent instance
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || null === $this->esi) {
return;
}
$this->esi->addSurrogateControl($event->getResponse());
}