本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseEvent::isMasterRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseEvent::isMasterRequest方法的具体用法?PHP GetResponseEvent::isMasterRequest怎么用?PHP GetResponseEvent::isMasterRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseEvent
的用法示例。
在下文中一共展示了GetResponseEvent::isMasterRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
$this->logger->debug('Entity builder listener: catch kernel.request event');
// If this is not a master request, skip handling
if (!$event->isMasterRequest()) {
$this->logger->debug('Entity builder listener: this is not master request, skip');
return;
}
// If content already prepared
if ($event->hasResponse()) {
$this->logger->debug('Entity builder listener: event already has response, skip');
return;
}
// Getting request
$request = $event->getRequest();
// Getting action
$apiServerAction = $event->getRequest()->attributes->get('apiAction');
/* @var $apiServerAction ApiServerAction */
// Something wrong
if (!$apiServerAction) {
$this->logger->error('Request parser listener: request has no apiAction attribute, throwing access denied exception');
throw new AccessDeniedHttpException();
}
// Creating request data entity
try {
$apiEntity = $apiServerAction->getRequestedEntity($request->attributes->get('apiData'));
} catch (\Exception $e) {
$this->logger->notice(sprintf('Request parser listener: unable to convert apiData to entity ("%s"), apiEntity set tu null', $e->getMessage()));
$apiEntity = null;
}
// Setting request attributes
$request->attributes->set('requestData', $apiEntity);
// Cleaning request attributes
$request->attributes->remove('apiData');
}
示例2: onKernelRequest
/**
* Logs master requests on event KernelEvents::REQUEST.
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->logRequest($event->getRequest());
}
示例3: onRequest
/**
* 请求完成后执行
*/
public function onRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$session = $request->getSession();
// 如果有 OpenID,则放行
if ($session->has('openid')) {
return;
}
// 排除资源文件
if (preg_match("^/(_(profiler|wdt)|css|images|js)/^", $request->getPathInfo())) {
return;
}
// 排除不需要 openid 的 URL
$currentRoute = $request->get('_route');
$currentParams = $request->get('_route_params');
if (in_array($currentRoute, $this->ignoreRoute)) {
return;
}
// 跳转到授权页,并把当前页作为参数(授权完成后还要跳转回来)
$currentUri = $this->router->generate($currentRoute, $currentParams);
$authorizeUrl = $this->router->generate('wechat_authorize', ['continue' => $currentUri]);
if (!$request->isXmlHttpRequest()) {
return $event->setResponse(new RedirectResponse($authorizeUrl));
}
$response = new JsonResponse(['failure' => '401 Unauthorized', 'redirect' => $authorizeUrl]);
return $event->setResponse($response);
}
示例4: onRequest
/**
* Add JSON handler to Whoops if Ajax request
*
* @param GetResponseEvent $event
*/
public function onRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest() || !$event->getRequest()->isXmlHttpRequest()) {
return;
}
$this->whoops->pushHandler(new JsonResponseHandler());
}
示例5: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
// Check master request
if (!$event->isMasterRequest()) {
return;
}
// Check excluded paths
$path = $event->getRequest()->getPathInfo();
if ($this->isExcludedPath($path)) {
return;
}
// Extract token
$headerToken = $this->tokenExtractor->extract($event->getRequest());
if (!is_string($headerToken)) {
throw new AuthenticationExpiredException('The access token is missing');
}
$token = $this->tokenVerificator->parsing($headerToken);
// Validate token
if (!$this->tokenVerificator->isValid($token)) {
throw new AuthenticationExpiredException('The access token is invalid');
}
// Store token
$this->tokenStorage->setToken($token);
// token
$operator = $token->getClaim('operatorId');
$event->getRequest()->request->set('operator', $operator);
$event->getRequest()->query->set('operator', $operator);
}
示例6: onRequest
/**
* Resume the session if it has been started previously or debugging is enabled
*
* @param GetResponseEvent $event
*/
public function onRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->manager->initialize($event->getRequest());
}
示例7: setThemeEngineRequestAttributes
/**
* The ThemeEngine::requestAttributes MUST be updated based on EACH Request and not only the initial Request.
* @param GetResponseEvent $event
*/
public function setThemeEngineRequestAttributes(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->themeEngine->setRequestAttributes($event->getRequest());
}
示例8: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
} else {
}
}
示例9: handle
/**
* Reads the Security Token from the session.
*
* @param GetResponseEvent $event A GetResponseEvent instance
*/
public function handle(GetResponseEvent $event)
{
if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
$this->registered = true;
}
$request = $event->getRequest();
$session = $request->hasPreviousSession() ? $request->getSession() : null;
if (null === $session || null === ($token = $session->get($this->sessionKey))) {
$this->tokenStorage->setToken(null);
return;
}
$token = unserialize($token);
if (null !== $this->logger) {
$this->logger->debug('Read existing security token from the session.', array('key' => $this->sessionKey));
}
if ($token instanceof TokenInterface) {
$token = $this->refreshUser($token);
} elseif (null !== $token) {
if (null !== $this->logger) {
$this->logger->warning('Expected a security token from the session, got something else.', array('key' => $this->sessionKey, 'received' => $token));
}
$token = null;
}
$this->tokenStorage->setToken($token);
}
示例10: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$routes = $this->router->getRouteCollection();
$route = $routes->get($request->attributes->get('_route'));
if (!$route->getOption('requires_license')) {
return;
}
if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') {
// Checking for whitelisted users
try {
$user = $this->tokenStorage->getToken()->getUser();
$today = date('Y-m-d');
if ($user instanceof UserInterface) {
$whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
foreach ($whitelist as $allowed) {
if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) {
return;
}
}
}
} catch (\Exception $e) {
// Do nothing
}
$url = $this->router->generate('atlassian_connect_unlicensed');
$response = new RedirectResponse($url);
$event->setResponse($response);
}
}
示例11: onKernelRequest
/**
* Logs master requests on event KernelEvents::REQUEST
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->logger->info('Received request');
}
示例12: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->sha = array();
}
示例13: handle
/**
* Reads the SecurityContext from the session.
*
* @param GetResponseEvent $event A GetResponseEvent instance
*/
public function handle(GetResponseEvent $event)
{
if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
$this->registered = true;
}
$request = $event->getRequest();
$session = $request->hasPreviousSession() ? $request->getSession() : null;
if (null === $session || null === ($token = $session->get('_security_' . $this->contextKey))) {
$this->context->setToken(null);
return;
}
$token = unserialize($token);
if (null !== $this->logger) {
$this->logger->debug('Read SecurityContext from the session');
}
if ($token instanceof TokenInterface) {
$token = $this->refreshUser($token);
} elseif (null !== $token) {
if (null !== $this->logger) {
$this->logger->warning(sprintf('Session includes a "%s" where a security token is expected', is_object($token) ? get_class($token) : gettype($token)));
}
$token = null;
}
$this->context->setToken($token);
}
示例14: onRequest
/**
* On Request received check the validity of the webpack cache.
*
* @param GetResponseEvent $event the response to send to te browser, we don't we only ensure the cache is there.
*/
public function onRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
$this->guard->rebuild();
}
示例15: onRequest
public function onRequest(GetResponseEvent $event)
{
$token = $this->storage->getToken();
$request = $event->getRequest();
$blackList = ['api.server.status', 'api.characters', 'api.character_create', 'template.serverstatus', 'api.character_create.validate', 'api.character_create.finalize', 'api.character.apicredentials', 'template.slidebutton', 'template.slidemenu'];
if (!$event->isMasterRequest() || $token === null || in_array('ROLE_SUPER_ADMIN', $this->getRolesArray($token->getRoles())) || in_array($request->attributes->get('_route'), $blackList) || !strstr(explode('::', $request->attributes->get('_controller'))[0], 'AppBundle')) {
$this->log->debug(sprintf('LISTENER Skipping %s', $request->attributes->get('_route')));
return;
}
if ($request->attributes->get('_controller') === 'AppBundle\\Controller\\Admin\\CharacterController::indexAction' && $this->session->has(self::ACTIVE_API_CHECK)) {
$this->session->getFlashBag()->add('danger', 'You must add a character with a valid NO EXPIRY API KEY in order to proceed');
$this->log->debug(sprintf('LISTENER Skipping %s', $request->attributes->get('_route')));
$this->session->remove(self::ACTIVE_API_CHECK);
return;
}
if ($token->isAuthenticated() && ($user = $this->storage->getToken()->getUser()) instanceof User) {
$characters = $this->doctrine->getRepository('AppBundle:Character')->findBy(['user' => $user]);
$activeKeys = $this->doctrine->getRepository('AppBundle:ApiCredentials')->getActiveKeyForUser($user);
if (count($characters) == 0 || count($activeKeys) <= 0) {
$this->log->debug(sprintf('LISTENER REDIRECT for %s', $request->attributes->get('_route')));
$response = new RedirectResponse($this->router->generate('characters'));
$this->session->set(self::ACTIVE_API_CHECK, time());
$event->setResponse($response);
}
}
}