本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\FilterResponseEvent::isMasterRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP FilterResponseEvent::isMasterRequest方法的具体用法?PHP FilterResponseEvent::isMasterRequest怎么用?PHP FilterResponseEvent::isMasterRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\FilterResponseEvent
的用法示例。
在下文中一共展示了FilterResponseEvent::isMasterRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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;
}
$configResolver = $this->container->get('ezpublish.config.resolver');
$domain = $configResolver->getParameter('domain', 'edgar_ez_cdn');
$extensions = $configResolver->getParameter('extensions', 'edgar_ez_cdn');
$http = $request->isSecure() ? 'https' : 'http';
if (empty($extensions)) {
return;
}
if (!is_array($extensions)) {
$extensions = array($extensions);
}
if (count($extensions) == 0) {
return;
}
$extensions = implode('|', $extensions);
$content = $response->getContent();
$pattern = '/="[^"]*\\/(css|js|var|bundles)\\/(.*)\\.(' . $extensions . ')([^"]*)"/i';
$replace = '="' . $http . '://' . $domain . '/${1}/${2}.${3}${4}"';
$content = preg_replace($pattern, $replace, $content);
$response->setContent($content);
}
示例3: onKernelResponse
/**
* add a rel=self Link header to the response
*
* @param FilterResponseEvent $event response listener event
*
* @return void
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
// don't do anything if it's not the master request
return;
}
$response = $event->getResponse();
$request = $event->getRequest();
$linkHeader = LinkHeader::fromResponse($response);
// extract various info from route
$routeName = $request->get('_route');
$routeParts = explode('.', $routeName);
$routeType = end($routeParts);
if ($routeType == 'post') {
$routeName = substr($routeName, 0, -4) . 'get';
}
/** if the request failed in the RestController, $request will not have an record id in
case of a POST and $router->generate() will fail. that's why we catch it and fail silently
by not including our header in the response. i hope that's a good compromise. **/
/** Nope, it's not a good compromise...catch and handle it where it happens.
* I will refactory this in another branch*/
$addHeader = true;
$url = '';
try {
$url = $this->router->generate($routeName, $this->generateParameters($routeType, $request), true);
} catch (\Exception $e) {
$addHeader = false;
}
if ($addHeader) {
// append rel=self link to link headers
$linkHeader->add(new LinkHeaderItem($url, array('rel' => 'self')));
// overwrite link headers with new headers
$response->headers->set('Link', (string) $linkHeader);
}
}
示例4: onKernelResponse
/**
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$this->wrapApiResponse) {
return;
}
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
// Only send back HTML if the requestor allows it
if (!$request->headers->has('Accept') || false === strpos($request->headers->get('Accept'), 'text/html')) {
return;
}
$response = $event->getResponse();
switch ($request->getRequestFormat()) {
case 'json':
$prettyprint_lang = 'js';
$content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT);
break;
case 'xml':
$prettyprint_lang = 'xml';
$content = $response->getContent();
break;
default:
return;
}
$response->setContent('<html><body>' . '<pre class="prettyprint lang-' . $prettyprint_lang . '">' . htmlspecialchars($content) . '</pre>' . '<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>' . '</body></html>');
// Set the request type to HTML
$response->headers->set('Content-Type', 'text/html; charset=UTF-8');
$request->setRequestFormat('html');
// Overwrite the original response
$event->setResponse($response);
}
示例5: onLateKernelResponse
public function onLateKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->sub->inRequest = false;
}
示例6: 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));
}
}
示例7: onKernelResponse
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->affiliate->record($event->getResponse());
}
示例8: onKernelResponse
/**
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
try {
if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) {
return;
}
} catch (AuthenticationCredentialsNotFoundException $e) {
return;
}
$request = $event->getRequest();
if ($request->isXmlHttpRequest()) {
return;
}
$response = $event->getResponse();
if ($response->isRedirection() || false === strpos($response->headers->get('Content-Type', ''), 'text/html')) {
return;
}
$html = $this->editor->renderEditor($response);
if (!empty($html)) {
$this->injectEditor($response, $html);
}
}
示例9: onRespond
/**
* Adds a cache tag if the 'user.permissions' cache context is present.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The event to process.
*/
public function onRespond(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
if (!$this->currentUser->isAnonymous()) {
return;
}
$response = $event->getResponse();
if (!$response instanceof CacheableResponseInterface) {
return;
}
// The 'user.permissions' cache context ensures that if the permissions for
// a role are modified, users are not served stale render cache content.
// But, when entire responses are cached in reverse proxies, the value for
// the cache context is never calculated, causing the stale response to not
// be invalidated. Therefore, when varying by permissions and the current
// user is the anonymous user, also add the cache tag for the 'anonymous'
// role.
if (in_array('user.permissions', $response->getCacheableMetadata()->getCacheContexts())) {
$per_permissions_response_for_anon = new CacheableMetadata();
$per_permissions_response_for_anon->setCacheTags(['config:user.role.anonymous']);
$response->addCacheableDependency($per_permissions_response_for_anon);
}
}
示例10: onKernelResponse
/**
* Logs master response on event KernelEvents::RESPONSE.
*
* @param FilterResponseEvent $event
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->logResponse($event->getResponse());
}
示例11: 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;
}
}
示例12: 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);
}
示例13: onKernelResponse
/**
*
* @param FilterResponseEvent $event
* @return void
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$response = $event->getResponse();
if (!$this->isCorsRequest($request)) {
return;
}
if ($this->isPreflightRequest($request)) {
if (!empty($this->app['cors.options']['allow_methods'])) {
$allowedMethods = $this->app['cors.options']['allow_methods'];
} else {
$allowedMethods = $this->app['cors.allowed_methods'];
}
if (!in_array($request->headers->get('Access-Control-Request-Method'), $allowedMethods)) {
return;
}
$response->headers->set('Access-Control-Allow-Headers', $request->headers->get('Access-Control-Request-Headers'));
$response->headers->set('Access-Control-Allow-Methods', $allowedMethods);
if (!empty($this->app['cors.options']['max_age'])) {
$response->headers->set('Access-Control-Max-Age', $this->app['cors.options']['max_age']);
}
} elseif (!empty($this->app['cors.options']['expose_headers'])) {
$response->headers->set('Access-Control-Expose-Headers', $this->app['cors.options']['expose_headers']);
}
$response->headers->set('Access-Control-Allow-Origin', '*');
if ($this->app['cors.options']['allow_credentials']) {
$response->headers->set('Access-Control-Allow-Credentials', '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 (!$event->isMasterRequest() || null === $this->surrogate) {
return;
}
$this->surrogate->addSurrogateControl($event->getResponse());
}