本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseEvent::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseEvent::getRequest方法的具体用法?PHP GetResponseEvent::getRequest怎么用?PHP GetResponseEvent::getRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseEvent
的用法示例。
在下文中一共展示了GetResponseEvent::getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setRequestLayout
public function setRequestLayout(GetResponseEvent $event)
{
$request = $event->getRequest();
// Get the necessary informations to check them in layout configurations
$path = $request->getPathInfo();
$host = $request->getHost();
$layouts = $this->config['layouts'];
// As a layout must be set, we force it to be empty if no layout is properly configured.
// Then this will throw an exception, and the user will be warned of the "no-layout" config problem.
$finalLayout = null;
foreach ($layouts as $layoutConfig) {
$match = false;
if ($layoutConfig['host'] && $host === $layoutConfig['host']) {
$match = true;
}
if ($layoutConfig['pattern'] && preg_match('~' . $layoutConfig['pattern'] . '~', $path)) {
$match = true;
}
if ($match) {
$finalLayout = $layoutConfig;
break;
}
}
if (null === $finalLayout || !$this->templating->exists($finalLayout['resource'])) {
throw new \Twig_Error_Loader(sprintf('Unable to find template %s for layout %s. The "layout" parameter must be a valid twig view to be used as a layout.', $finalLayout['resource'], $finalLayout['name']), 0, $finalLayout['resource']);
}
$event->getRequest()->attributes->set('_orbitale_cms_layout', $finalLayout);
}
示例2: 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);
}
示例3: handleEvent
private function handleEvent(GetResponseEvent $event)
{
/** @var SessionHandler $sessionHandler */
$sessionHandler = $this->container->get('ra.security.authentication.session_handler');
// reinstate the token from the session. Could be expanded with logout check if needed
if ($this->getTokenStorage()->getToken()) {
return;
}
/** @var SamlInteractionProvider $samlInteractionProvider */
$samlInteractionProvider = $this->container->get('ra.security.authentication.saml');
if (!$samlInteractionProvider->isSamlAuthenticationInitiated()) {
$sessionHandler->setCurrentRequestUri($event->getRequest()->getUri());
$event->setResponse($samlInteractionProvider->initiateSamlRequest());
/** @var SamlAuthenticationLogger $logger */
$logger = $this->container->get('surfnet_saml.logger')->forAuthentication($sessionHandler->getRequestId());
$logger->notice('Sending AuthnRequest');
return;
}
/** @var SamlAuthenticationLogger $logger */
$logger = $this->container->get('surfnet_saml.logger')->forAuthentication($sessionHandler->getRequestId());
$expectedInResponseTo = $sessionHandler->getRequestId();
try {
$assertion = $samlInteractionProvider->processSamlResponse($event->getRequest());
} catch (PreconditionNotMetException $e) {
$logger->notice(sprintf('SAML response precondition not met: "%s"', $e->getMessage()));
$event->setResponse($this->renderPreconditionExceptionResponse($e));
return;
} catch (Exception $e) {
$logger->error(sprintf('Failed SAMLResponse Parsing: "%s"', $e->getMessage()));
throw new AuthenticationException('Failed SAMLResponse parsing', 0, $e);
}
if (!InResponseTo::assertEquals($assertion, $expectedInResponseTo)) {
$logger->error('Unknown or unexpected InResponseTo in SAMLResponse');
throw new AuthenticationException('Unknown or unexpected InResponseTo in SAMLResponse');
}
$logger->notice('Successfully processed SAMLResponse, attempting to authenticate');
$loaResolutionService = $this->container->get('surfnet_stepup.service.loa_resolution');
$loa = $loaResolutionService->getLoa($assertion->getAuthnContextClassRef());
$token = new SamlToken($loa);
$token->assertion = $assertion;
/** @var AuthenticationProviderManager $authenticationManager */
$authenticationManager = $this->container->get('security.authentication.manager');
try {
$authToken = $authenticationManager->authenticate($token);
} catch (BadCredentialsException $exception) {
$logger->error(sprintf('Bad credentials, reason: "%s"', $exception->getMessage()), ['exception' => $exception]);
$event->setResponse($this->renderBadCredentialsResponse($exception));
return;
} catch (AuthenticationException $failed) {
$logger->error(sprintf('Authentication Failed, reason: "%s"', $failed->getMessage()), ['exception' => $failed]);
$event->setResponse($this->renderAuthenticationExceptionResponse($failed));
return;
}
// for the current request
$this->getTokenStorage()->setToken($authToken);
// migrate the session to prevent session hijacking
$sessionHandler->migrate();
$event->setResponse(new RedirectResponse($sessionHandler->getCurrentRequestUri()));
$logger->notice('Authentication succeeded, redirecting to original location');
}
示例4: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if ($this->kernel->getEnvironment() != "dev") {
if (preg_match("/\\/api\\//", $event->getRequest()->getUri())) {
$requestUri = $event->getRequest()->getUri();
$requestMethod = $event->getRequest()->getMethod();
if ($requestMethod !== "GET") {
$token = $this->context->getToken();
if (isset($token)) {
$user = $token->getUser();
if (!isset($user) || "anon." === $user) {
if (!$event->getRequest()->query->has('api_key')) {
$event->setResponse(new Response(json_encode(array("code" => 401, "message" => "The request requires user authentication")), 401));
}
}
} else {
$event->setResponse(new Response(json_encode(array("code" => 401, "message" => "The request requires user authentication")), 401));
}
}
}
}
$request = $event->getRequest();
if (!count($request->request->all()) && in_array($request->getMethod(), array('POST', 'PUT', 'PATCH', 'DELETE'))) {
$contentType = $request->headers->get('Content-Type');
$format = null === $contentType ? $request->getRequestFormat() : $request->getFormat($contentType);
if (!$this->decoderProvider->supports($format)) {
return;
}
$decoder = $this->decoderProvider->getDecoder($format);
$data = $decoder->decode($request->getContent(), $format);
if (is_array($data)) {
$request->request = new ParameterBag($data);
}
}
}
示例5: onRequest
/**
* Resolve issue on request
*
* @param GetResponseEvent $event GetResponseEvent event
*
* @return void
*/
public function onRequest(GetResponseEvent $event)
{
$onAdminInterface = strpos($event->getRequest()->getRequestUri(), '/admin');
if ($onAdminInterface === false && $event->getRequest()->get('_route') != 'newscoop_get_img') {
$this->issueService->issueResolver($event->getRequest());
}
}
示例6: switchLocaleOnRequest
/**
* Checks if after a reload if the locale has changed.
* If the user is logged in, the route is the default application route and the locale has changed,
* the user locale will be modified
*
* @param GetResponseEvent $event
*/
public function switchLocaleOnRequest(GetResponseEvent $event)
{
// no user is set in the access token
// which means that no system user is authenticated and
// that trigger is irrelevant
if (null === ($user = $this->userFetcher->resolve())) {
return;
}
$userLocale = $user->getSimpleProfile()->getLocale();
if ($userLocale === ($cookie = $event->getRequest()->cookies->get('locale'))) {
return;
}
$validLocale = true;
try {
$user->changeUserLocale($cookie);
} catch (ChangeUserLocaleException $ex) {
$validLocale = false;
$request = $event->getRequest();
$request->cookies->remove('locale');
$request->setLocale($userLocale);
$request->attributes->set('_locale', $userLocale);
}
// if the locale is invalid,
// the cookie will be fixed in the response event
if (!$validLocale) {
$this->fixCookie = true;
return;
}
$this->userRepository->modify($user);
}
示例7: onKernelRequest
/**
* If users flag isFirstLogin is true redirect to change password page.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
// Don't do anything if it's not the master request or another firewall than "secured"
$isSecuredArea = (bool) preg_match('/^\\/secured/', $event->getRequest()->getPathInfo());
if (HttpKernel::MASTER_REQUEST != $event->getRequestType() || !$isSecuredArea) {
return;
}
$token = $this->tokenStorage->getToken();
// Bypass listener if token does not match UsernamePasswordToken
if (!$token instanceof UsernamePasswordToken) {
return;
}
$changePasswordUrl = $this->router->generate('OpitOpitHrmUserBundle_user_change_password', array(), true);
$excludedRoutes = array($this->router->generate('OpitOpitHrmUserBundle_logout', array(), true), $changePasswordUrl);
if (null !== $token && is_object($token->getUser())) {
// Bypass the change password page if user has ldap auth enabled
if ($token->getUser()->isLdapEnabled()) {
return;
}
if (in_array($event->getRequest()->getUri(), $excludedRoutes)) {
return;
}
if ($token->getUser()->getIsFirstLogin()) {
$event->setResponse(new RedirectResponse($changePasswordUrl));
}
}
}
示例8: testAnalyze
public function testAnalyze()
{
$this->getResponseEvent->isMasterRequest()->willReturn(true);
$this->getResponseEvent->getRequest()->willReturn(new Request());
$this->requestListener->onKernelRequest($this->getResponseEvent->reveal());
$this->requestAnalyzer->analyze(Argument::any())->shouldHaveBeenCalled();
}
示例9: handle
public function handle(GetResponseEvent $event)
{
if (!$this->cas->isValidationRequest($event->getRequest())) {
return;
}
if (null !== $this->logger) {
$this->logger->debug(sprintf('Checking secure context token: %s', $this->securityContext->getToken()));
}
list($username, $attributes) = $this->getTokenData($event->getRequest());
if (null !== ($token = $this->securityContext->getToken())) {
if ($token instanceof CasAuthenticationToken && $token->isAuthenticated() && (string) $token === $username) {
return;
}
}
try {
$token = $this->authenticationManager->authenticate(new CasAuthenticationToken($username, $attributes));
if (null !== $this->logger) {
$this->logger->debug(sprintf('Authentication success: %s', $token));
}
$this->securityContext->setToken($token);
} catch (AuthenticationException $failed) {
$this->securityContext->setToken(null);
if (null !== $this->logger) {
$this->logger->debug(sprintf("Cleared security context due to exception: %s", $failed->getMessage()));
}
}
}
示例10: checkToto
public function checkToto(GetResponseEvent $event)
{
$tot = $event->getRequest()->query->get('toto');
if (!is_null($tot)) {
$event->getRequest()->query->set('tata', $tot);
}
}
示例11: purlCheckNodeContext
/**
* Checks if a node's type requires a redirect.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event to process.
*/
public function purlCheckNodeContext(GetResponseEvent $event, $eventName, EventDispatcherInterface $dispatcher_interface)
{
$route_options = $this->routeMatch->getRouteObject()->getOptions();
$isAdminRoute = array_key_exists('_admin_route', $route_options) && $route_options['_admin_route'];
if (!$isAdminRoute && ($matched = $this->matchedModifiers->getMatched() && ($entity = $this->routeMatch->getParameter('node')))) {
$node_type = $this->entityStorage->load($entity->bundle());
$purl_settings = $node_type->getThirdPartySettings('purl');
if (!isset($purl_settings['keep_context']) || !$purl_settings['keep_context']) {
$url = \Drupal\Core\Url::fromRoute($this->routeMatch->getRouteName(), $this->routeMatch->getRawParameters()->all(), ['host' => Settings::get('purl_base_domain'), 'absolute' => TRUE]);
try {
$redirect_response = new TrustedRedirectResponse($url->toString());
$redirect_response->getCacheableMetadata()->setCacheMaxAge(0);
$modifiers = $event->getRequest()->attributes->get('purl.matched_modifiers', []);
$new_event = new ExitedContextEvent($event->getRequest(), $redirect_response, $this->routeMatch, $modifiers);
$dispatcher_interface->dispatch(PurlEvents::EXITED_CONTEXT, $new_event);
$event->setResponse($new_event->getResponse());
return;
} catch (RedirectLoopException $e) {
\Drupal::logger('redirect')->warning($e->getMessage());
$response = new Response();
$response->setStatusCode(503);
$response->setContent('Service unavailable');
$event->setResponse($response);
return;
}
}
}
}
示例12: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
return;
}
if ($event->getRequest()->get("_route") == $this->changePasswordRoute || substr($event->getRequest()->get("_route"), 0, 8) == "_assetic") {
return;
}
$token = $this->security->getToken();
if (!$token) {
return;
}
$user = $token->getUser();
if (!$user) {
return;
}
$lastUserPassword = $this->em->getRepository("ACSEOChangePasswordBundle:PasswordHistory")->findOneBy(array("user" => $user), array("createdAt" => "DESC"), 1);
if (!$lastUserPassword) {
return;
}
$lastPasswordDate = $lastUserPassword->getCreatedAt();
if ($lastPasswordDate->add(new \DateInterval($this->passwordExpireAfter)) < new \Datetime()) {
if ($this->enableFlashbagMessage) {
$event->getRequest()->getSession()->getFlashBag()->add("danger", "Votre mot de passe a expiré, vous devez en saisir un nouveau");
}
$response = new RedirectResponse($this->router->generate($this->changePasswordRoute));
$event->setResponse($response);
}
}
示例13: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}
$attributes = $event->getRequest()->attributes;
//if have any route param return null
if (!$attributes->has('_route_params')) {
return;
}
//for all route params
foreach ($attributes->get('_route_params') as $paramKey => $param) {
// if there is a param which matches with id key
if (preg_match('/id/', $paramKey)) {
/**
* throw not found exception because pg type db max value is 2147483647
* @look {https://www.postgresql.org/docs/9.1/static/datatype-numeric.html}
*/
if ((int) $param && (int) $param > 2147483647) {
//throw new NotFoundHttpException;
}
}
}
}
示例14: onKernelRequest
/**
* @param GetResponseEvent $event
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* @return bool
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (strpos($event->getRequest()->attributes->get('_controller'), 'Api\\Resource') !== false) {
header('Access-Control-Allow-Origin: *');
$controller = explode('::', $event->getRequest()->attributes->get('_controller'));
$reflection = new \ReflectionMethod($controller[0], $controller[1]);
$scopeAnnotation = $this->reader->getMethodAnnotation($reflection, 'Etu\\Core\\ApiBundle\\Framework\\Annotation\\Scope');
if ($scopeAnnotation) {
$requiredScope = $scopeAnnotation->value;
} else {
$requiredScope = null;
}
if (!$requiredScope) {
$requiredScope = 'public';
}
$request = $event->getRequest();
$token = $request->query->get('access_token');
$access = $this->server->checkAccess($token, $requiredScope);
if (!$access->isGranted()) {
$event->setResponse($this->formatter->format($event->getRequest(), ['error' => $access->getError(), 'error_message' => $access->getErrorMessage()], 403));
} else {
$event->getRequest()->attributes->set('_oauth_token', $access->getToken());
}
}
}
示例15: onKernelRequest
/**
* Setup the route parameters.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public function onKernelRequest(GetResponseEvent $event)
{
LoggerRegistry::debug('EngineRouterListener performing start() on REQUEST event');
$this->setRoutingAttributes($event->getRequest());
$this->setTemplateAttributes($event->getRequest());
LoggerRegistry::debug('EngineRouterListener will proceed with standard rendering');
}