本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseEvent::stopPropagation方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseEvent::stopPropagation方法的具体用法?PHP GetResponseEvent::stopPropagation怎么用?PHP GetResponseEvent::stopPropagation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseEvent
的用法示例。
在下文中一共展示了GetResponseEvent::stopPropagation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
public function handle(GetResponseEvent $event)
{
// getting request
$request = $event->getRequest();
// getting attributes
$apiClientToken = $request->attributes->get('apiClientToken');
$apiUserToken = $request->attributes->get('apiUserToken');
$apiServerAction = $request->attributes->get('apiAction');
/* @var $apiServerAction ApiServerAction */
// cleaning credentials and interface name
$request->attributes->remove('apiClientToken');
$request->attributes->remove('apiUserToken');
// creating token
$token = new Token($apiServerAction->getApiServerInterface());
$token->setCredentials([$apiClientToken, $apiUserToken]);
try {
// authenticating
$authenticatedToken = $this->authenticationManager->authenticate($token);
$this->tokenStorage->setToken($authenticatedToken);
// getting authenticated user
$user = $authenticatedToken->getUser();
/* @var $user User */
// setting request attributes
$request->attributes->set('apiConnection', $user->getApiConnection());
$request->attributes->set('apiClient', $user->getApiClient());
$request->attributes->set('apiUser', $user->getApiUser());
} catch (\Exception $e) {
$event->stopPropagation();
throw new AccessDeniedHttpException(null, $e);
}
}
示例2: redirectToSsl
private function redirectToSsl(GetResponseEvent $event)
{
$event->stopPropagation();
$redirect = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header("HTTP/1.1 302 Found");
header("Location: {$redirect}");
exit;
}
示例3: setNotAcceptableError
private function setNotAcceptableError(GetResponseEvent $event)
{
$responseFactory = new ResponseFactory($this->accept->getDefault());
$catalogResponse = new \Dafiti\Silex\Response(HttpFoundation\Response::HTTP_NOT_ACCEPTABLE);
$response = $responseFactory->create($catalogResponse);
$event->setResponse($response);
$event->stopPropagation();
}
示例4: onMaintenance
public function onMaintenance(GetResponseEvent $event)
{
if ($this->maintenance == true) {
$content = $this->twig->render('TroiswaFrontBundle:Maintenance:index.html.twig');
$event->setResponse(new Response($content, 503));
$event->stopPropagation();
}
}
示例5: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
$debug = in_array($this->environnement, ['test', 'dev']);
if ($this->isMaintenance && !$debug) {
$content = $this->twig->render('TroiswaBackBundle:Maintenance:index.html.twig');
$event->setResponse(new Response($content, 503));
$event->stopPropagation();
}
}
示例6: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if ($request->headers->has('Access-Control-Request-Headers') and $request->headers->has('Access-Control-Request-Method')) {
$response = new Response();
$response->headers->add(['Access-Control-Allow-Headers' => $request->headers->get('Access-Control-Request-Headers'), 'Access-Control-Allow-Methods' => $request->headers->get('Access-Control-Request-Method'), 'Access-Control-Allow-Origin' => '*']);
$event->setResponse($response);
$event->stopPropagation();
}
}
示例7: miseEnMaintenance
public function miseEnMaintenance(GetResponseEvent $event)
{
//die(dump($this->maintenance, $this->environnement));
$contenuHTML = $this->twig->render('TroiswaBackBundle:Other:maintenance.html.twig');
if ($this->maintenance && $this->environnement == 'prod') {
$event->setResponse(new Response($contenuHTML, 503));
// contenu et code maintenance
$event->stopPropagation();
}
}
示例8: handle
public function handle(GetResponseEvent $event)
{
try {
$token = new Token();
$authenticatedToken = $this->authenticationManager->authenticate($token);
$this->tokenStorage->setToken($authenticatedToken);
} catch (\Exception $e) {
$event->stopPropagation();
throw new AccessDeniedHttpException(null, $e);
}
}
示例9: miseEnMaintenance
public function miseEnMaintenance(GetResponseEvent $event)
{
//Si je suis en maintenance et qu'on est en environnement de prod
if ($this->maintenance && $this->environnement == 'prod') {
$contenuHTML = $this->twig->render('WaBackBundle:Partial:maintenance.html.twig');
//Par défaut le code respone est 200 on le passe en 503 = maintenance
$event->setResponse(new Response($contenuHTML, 503));
// contenu et code maintenance
$event->stopPropagation();
}
}
示例10: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
// Si no es una peticion maestra ignora el evento
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
$rules = $this->Config->get('security', 'access_control');
foreach ($rules as $rule) {
$requestMatcher = new RequestMatcher($rule['pattern']);
// Si es verdadero es una area restringida
if ($requestMatcher->matches($request)) {
// Busca en la session si existe una tarjeta del usuario
// La tajeta debe ser un objecto de serializado que implemente la interfaz CardInterface
$user_card = $this->CardManager->getCard('user_card');
// Si la tarjeta existe
if ($user_card) {
$role = $user_card->getRole();
// Si no tiene el rol correcto retorna una respuesta para redireccionar
if ($role == null || strtoupper($role) != strtoupper($rule['role'])) {
// Detiene la propagacion del evento
$event->stopPropagation();
if ($request->isXmlHttpRequest()) {
$event->setResponse(new JsonResponse(array('status' => 'forbidden')), Response::HTTP_FORBIDDEN);
} else {
$event->setResponse(new redirectResponse(Util::buildUrl($rule['forbidden_route'])));
}
return;
}
} else {
$event->stopPropagation();
if ($request->isXmlHttpRequest()) {
$event->setResponse(new JsonResponse(array('status' => 'forbidden')), Response::HTTP_FORBIDDEN);
} else {
$event->setResponse(new redirectResponse(Util::buildUrl($rule['login_route'])));
}
return;
}
}
}
}
示例11: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}
$result = $this->securityManager->vote();
if ($result === SecurityManager::ACCESS_DENIED_DEFER) {
$event->stopPropagation();
$redirectUrl = $this->router->generate($this->forceAccountRecovery['route_recover_account']['name'], $this->forceAccountRecovery['route_recover_account']['params']);
$event->setResponse(new RedirectResponse($redirectUrl));
}
}
示例12: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
$maintenanceUntil = $this->container->hasParameter('underMaintenanceUntil') ? $this->container->getParameter('underMaintenanceUntil') : false;
$maintenance = $this->container->hasParameter('maintenance') ? $this->container->getParameter('maintenance') : false;
$debug = in_array($this->container->get('kernel')->getEnvironment(), array('test', 'dev'));
if ($maintenance && !$debug) {
$engine = $this->container->get('templating');
$content = $engine->render('::maintenance.html.twig', array('maintenanceUntil' => $maintenanceUntil));
$event->setResponse(new Response($content, 503));
$event->stopPropagation();
}
}
示例13: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if ($this->installed || $event->getRequestType() !== HttpKernel::MASTER_REQUEST) {
return;
}
$route = $event->getRequest()->get('_route');
if (!in_array($route, $this->allowRoutes)) {
$response = new RedirectResponse($this->router->generate(self::INSTALLER_ROUTE));
$event->setResponse($response);
$event->stopPropagation();
}
}
示例14: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}
/* @var $server ServerBag */
$server = $event->getRequest()->server;
// Check that the access to the application by the local computer or local network
if ($server->get('HTTP_CLIENT_IP') || $server->get('HTTP_X_FORWARDED_FOR') || !($addr = $server->get('REMOTE_ADDR')) || !$this->isLocalHost($addr) && !$this->isLocalNetwork($addr)) {
$response = new Response('You are not allowed to access this application.', Response::HTTP_FORBIDDEN);
$event->setResponse($response->setPublic());
$event->stopPropagation();
}
}
示例15: onRequest
public function onRequest(GetResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
return;
}
if (!$this->installed) {
$allowedRoutes = array('oro_installer_flow', 'sylius_flow_display', 'sylius_flow_forward');
if ($this->debug) {
$allowedRoutes = array_merge($allowedRoutes, array('_wdt', '_profiler', '_profiler_search', '_profiler_search_bar', '_profiler_search_results', '_profiler_router'));
}
if (!in_array($event->getRequest()->get('_route'), $allowedRoutes)) {
$event->setResponse(new RedirectResponse($event->getRequest()->getBasePath() . '/install.php'));
}
$event->stopPropagation();
} else {
// allow open the installer even if the application is already installed
// this is required because we are clearing the cache on the last installation step
// and as the result the login page is appeared instead of the final installer page
if ($event->getRequest()->attributes->get('scenarioAlias') === 'oro_installer' && ($event->getRequest()->attributes->get('_route') === 'sylius_flow_forward' || $event->getRequest()->attributes->get('_route') === 'sylius_flow_display')) {
$event->stopPropagation();
}
}
}