本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseEvent::getDispatcher方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseEvent::getDispatcher方法的具体用法?PHP GetResponseEvent::getDispatcher怎么用?PHP GetResponseEvent::getDispatcher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\GetResponseEvent
的用法示例。
在下文中一共展示了GetResponseEvent::getDispatcher方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
$session = $request->getSession();
$bag_configuration = new BagConfiguration();
if ($session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE))->has('sfGuardSecurityUser')) {
$sf1_guard_security_user = $session->getBag($bag_configuration->getNamespace(BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE))->get('sfGuardSecurityUser');
$username = $sf1_guard_security_user['username'];
$token = new MinisterioUserBridgeToken();
$token->setUser($username);
try {
$authToken = $this->authenticationManager->authenticate($token);
$this->tokenStorage->setToken($authToken);
$event->getDispatcher()->dispatch(self::AUTHENTICATED_EVENT, new MinisterioUserBridgeAuthenticatedEvent($authToken));
return;
} catch (AuthenticationException $failed) {
// ... you might log something here
// To deny the authentication clear the token. This will redirect to the login page.
// Make sure to only clear your token, not those of other authentication listeners.
// $token = $this->tokenStorage->getToken();
// if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) {
// $this->tokenStorage->setToken(null);
// }
// return;
}
}
// By default deny authorization
$response = new Response("", Response::HTTP_TEMPORARY_REDIRECT, array("Location" => $this->container->getParameter('logout_url')));
$event->setResponse($response);
}
示例2: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
// If we have a somebody elses controller, just exit (for now)
$controller = $request->attributes->get('_controller');
if (false === strpos($controller, 'ZenMagick')) {
return;
}
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
$dispatcher = $event->getDispatcher();
$request->getSession()->restorePersistedServices();
$dispatcher->dispatch('request_ready', new GenericEvent($this, array('request' => $request)));
$dispatcher->dispatch('container_ready', new GenericEvent($this, array('request' => $request)));
$this->container->get('sacsManager')->authorize($request, $request->getRequestId(), $request->getAccount());
foreach ($this->container->get('containerTagService')->findTaggedServiceIds('zenmagick.http.session.validator') as $id => $args) {
if (null != ($validator = $this->container->get($id)) && $validator instanceof SessionValidator) {
$session = $request->getSession();
if (!$validator->isValidSession($request, $session)) {
$session->getFlashBag()->error('Invalid session');
$session->migrate();
$event->setResponse(new RedirectResponse($request->server->get('HTTP_REFERER')));
}
}
}
}
示例3: handle
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
$token = $this->_context->getToken();
$errmsg = '';
if (null !== $request->request->get('login') && null !== $request->request->get('password')) {
$token = new UsernamePasswordToken($request->request->get('login'), $request->request->get('password'));
$token->setUser($request->request->get('login'), $request->request->get('password'));
try {
$token = $this->_authenticationManager->authenticate($token);
if (null !== $this->_logger) {
$this->_logger->info(sprintf('Authentication request succeed for user "%s"', $token->getUsername()));
}
} catch (\Symfony\Component\Security\Core\Exception\AuthenticationException $e) {
$event->getDispatcher()->dispatch(\Symfony\Component\Security\Core\AuthenticationEvents::AUTHENTICATION_FAILURE, new \Symfony\Component\Security\Core\Event\AuthenticationFailureEvent($token, $e));
$errmsg = $e->getMessage();
if (null !== $this->_logger) {
$this->_logger->info(sprintf('Authentication request failed for user "%s": %s', $token->getUsername(), $e->getMessage()));
}
} catch (\Exception $e) {
$errmsg = $e->getMessage();
if (null !== $this->_logger) {
$this->_logger->info(sprintf('Authentication request failed for user "%s": %s', $token->getUsername(), $e->getMessage()));
}
}
}
if (is_a($token, 'BackBee\\Security\\Token\\UsernamePasswordToken') && $errmsg != '') {
if (null !== $this->_login_path) {
if (preg_match('/%(.*)%/s', $this->_login_path, $matches)) {
if ($this->_context->getApplication()->getContainer()->hasParameter($matches[1])) {
$this->_login_path = $this->_context->getApplication()->getContainer()->getParameter($matches[1]);
}
}
$redirect = $request->query->get('redirect');
if (null === $redirect) {
$redirect = $request->request->get('redirect', '');
}
if ('' === $redirect) {
$redirect = $request->getPathInfo();
}
if (null !== ($qs = $request->getQueryString())) {
$redirect .= '?' . $qs;
}
$response = new RedirectResponse($event->getRequest()->getUriForPath($this->_login_path . '?redirect=' . urlencode($redirect) . '&errmsg=' . urlencode($errmsg) . '&login=' . urlencode($request->request->get('login'))));
$event->setResponse($response);
return;
}
$response = new Response();
$response->setStatusCode(403);
$event->setResponse($response);
}
if (null !== $token && is_a($token, 'BackBee\\Security\\Token\\UsernamePasswordToken')) {
$this->_context->setToken($token);
if ($request->request->get('redirect')) {
$response = new RedirectResponse($request->getBaseUrl() . $request->request->get('redirect'));
$event->setResponse($response);
}
}
}
示例4: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
//$logger = $event->
$dispatcher = $event->getDispatcher();
$ofwnGateway = new Ofwn\OfwnGateway();
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$ofwnGateway->handleRequest($event, $this->router);
// $dispatcher->addListener('kernel.request', array($ofwnGateway, 'handleRequest'), 999);
}
}
示例5: rememberMeLoader
public function rememberMeLoader(GetResponseEvent $event)
{
/** @var \Thelia\Core\HttpFoundation\Request $request */
$request = $event->getRequest();
/** @var \Thelia\Core\HttpFoundation\Session\Session $session */
$session = $request->getSession();
if (null === $session->getCustomerUser()) {
// Check customer remember me token
$this->getRememberMeCustomer($request, $session, $event->getDispatcher());
}
// Check admin remember me token
if (null === $session->getAdminUser()) {
$this->getRememberMeAdmin($request, $session);
}
}
示例6: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
/* @var $request \Symfony\Component\HttpFoundation\Request */
$request = $event->getRequest();
if ($request->attributes->has('hasGrid')) {
if ($request->isMethod('POST')) {
$data = array();
foreach ($this->fields as $field) {
if ($request->request->has($field)) {
$data[$field] = $request->request->get($field);
}
}
$executeEvent = new DataGridEvent();
$executeEvent->setData($data);
$event->getDispatcher()->dispatch('grid.event', $executeEvent);
if ($request->isXmlHttpRequest()) {
$response = new JsonResponse(array('post' => $_POST, 'success' => true));
// $event->setResponse($response);
}
}
}
}
示例7: onKernelRequest
/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->getRequest()->headers->has('link')) {
return;
}
$links = array();
$header = $event->getRequest()->headers->get('link');
/*
* Due to limitations, multiple same-name headers are sent as comma
* separated values.
*
* This breaks those headers into Link headers following the format
* http://tools.ietf.org/html/rfc2068#section-19.6.2.4
*/
while (preg_match('/^((?:[^"]|"[^"]*")*?),/', $header, $matches)) {
$header = trim(substr($header, strlen($matches[0])));
$links[] = $matches[1];
}
if ($header) {
$links[] = $header;
}
$requestMethod = $this->urlMatcher->getContext()->getMethod();
// The controller resolver needs a request to resolve the controller.
$stubRequest = new Request();
foreach ($links as $idx => $link) {
// Force the GET method to avoid the use of the
// previous method (LINK/UNLINK)
$this->urlMatcher->getContext()->setMethod('GET');
$linkParams = explode(';', trim($link));
$resourceType = null;
if (count($linkParams) > 1) {
$resourceType = trim(preg_replace('/<|>/', '', $linkParams[1]));
$resourceType = str_replace("\"", "", str_replace("rel=", "", $resourceType));
}
$resource = array_shift($linkParams);
$resource = preg_replace('/<|>/', '', $resource);
$tempRequest = Request::create($resource);
try {
$route = $this->urlMatcher->match($tempRequest->getRequestUri());
} catch (\Exception $e) {
// If we don't have a matching route we return the original Link header
continue;
}
if (strpos($route['_route'], 'newscoop_gimme_') === false) {
return;
}
$stubRequest->attributes->replace($route);
$stubRequest->server = $event->getRequest()->server;
if (false === ($controller = $this->resolver->getController($stubRequest))) {
continue;
}
$subEvent = new FilterControllerEvent($event->getKernel(), $controller, $stubRequest, HttpKernelInterface::SUB_REQUEST);
$kernelSubEvent = new GetResponseEvent($event->getKernel(), $stubRequest, HttpKernelInterface::SUB_REQUEST);
$event->getDispatcher()->dispatch(KernelEvents::REQUEST, $kernelSubEvent);
$event->getDispatcher()->dispatch(KernelEvents::CONTROLLER, $subEvent);
$controller = $subEvent->getController();
$arguments = $this->resolver->getArguments($stubRequest, $controller);
try {
$result = call_user_func_array($controller, $arguments);
// Our api returns objects for single resources
if (!is_object($result)) {
continue;
}
$links[$idx] = array('object' => $result, 'resourceType' => $resourceType);
} catch (\Exception $e) {
$links[$idx] = array('object' => $e, 'resourceType' => 'exception');
continue;
}
}
$event->getRequest()->attributes->set('links', $links);
$this->urlMatcher->getContext()->setMethod($requestMethod);
}
示例8: onInit
/**
* Initialise Zikula.
*
* Carries out a number of initialisation tasks to get Zikula up and
* running.
*
* @param integer $stage Stage to load.
*
* @return boolean True initialisation successful false otherwise.
*/
public function onInit(GetResponseEvent $event)
{
if ($event->getRequestType() === HttpKernelInterface::SUB_REQUEST) {
return;
}
$this->dispatcher = $event->getDispatcher();
$this->stage = $stage = self::STAGE_ALL;
$coreInitEvent = new GenericEvent($this);
$coreInitEvent['request'] = $event->getRequest();
// store the load stages in a global so other API's can check whats loaded
$this->dispatcher->dispatch(CoreEvents::PREINIT, new GenericEvent($this));
// // Initialise and load configuration
// if ($stage & self::STAGE_CONFIG) {
// // error reporting
// if (!\System::isInstalling()) {
// // this is here because it depends on the config.php loading.
// $event = new GenericEvent(null, array('stage' => $stage));
// $this->dispatcher->dispatch(CoreEvents::ERRORREPORTING, $event);
// }
//
// // initialise custom event listeners from config.php settings
// $coreInitEvent->setArg('stage', self::STAGE_CONFIG);
// $this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent);
// }
// // Check that Zikula is installed before continuing
// if (\System::getVar('installed') == 0 && !\System::isInstalling()) {
// $response = new RedirectResponse(\System::getBaseUrl().'install.php?notinstalled');
// $response->send();
// \System::shutdown();
// }
if ($stage & self::STAGE_DB) {
try {
$dbEvent = new GenericEvent();
$this->dispatcher->dispatch('doctrine.init_connection', $dbEvent);
$dbEvent = new GenericEvent($this, array('stage' => self::STAGE_DB));
$this->dispatcher->dispatch(CoreEvents::INIT, $dbEvent);
} catch (\PDOException $e) {
if (!\System::isInstalling()) {
header('HTTP/1.1 503 Service Unavailable');
require_once \System::getSystemErrorTemplate('dbconnectionerror.tpl');
\System::shutDown();
} else {
return false;
}
}
}
if ($stage & self::STAGE_TABLES) {
// Initialise dbtables
\ModUtil::initCoreVars();
\ModUtil::dbInfoLoad('SettingsModule', 'SettingsModule');
\ModUtil::dbInfoLoad('ThemeModule', 'ThemeModule');
\ModUtil::dbInfoLoad('UsersModule', 'UsersModule');
\ModUtil::dbInfoLoad('GroupsModule', 'GroupsModule');
\ModUtil::dbInfoLoad('PermissionsModule', 'PermissionsModule');
\ModUtil::dbInfoLoad('CategoriesModule', 'CategoriesModule');
if (!\System::isInstalling()) {
\ModUtil::registerAutoloaders();
}
$coreInitEvent->setArg('stage', self::STAGE_TABLES);
$this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent);
}
if ($stage & self::STAGE_SESSIONS) {
\SessionUtil::requireSession();
$coreInitEvent->setArg('stage', self::STAGE_SESSIONS);
$this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent);
}
// Have to load in this order specifically since we cant setup the languages until we've decoded the URL if required (drak)
// start block
if ($stage & self::STAGE_LANGS) {
$lang = \ZLanguage::getInstance();
}
if ($stage & self::STAGE_DECODEURLS) {
\System::queryStringDecode();
$coreInitEvent->setArg('stage', self::STAGE_DECODEURLS);
$this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent);
}
if ($stage & self::STAGE_LANGS) {
$lang->setup();
$coreInitEvent->setArg('stage', self::STAGE_LANGS);
$this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent);
}
// end block
if ($stage & self::STAGE_MODS) {
// Set compression on if desired
if (\System::getVar('UseCompression') == 1) {
//ob_start("ob_gzhandler");
}
\ModUtil::load('SecurityCenter');
$coreInitEvent->setArg('stage', self::STAGE_MODS);
$this->dispatcher->dispatch(CoreEvents::INIT, $coreInitEvent);
//.........这里部分代码省略.........
示例9: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
if (!$event->getRequest()->headers->has('link')) {
return;
}
$links = array();
$header = $event->getRequest()->headers->get('link');
/*
* Due to limitations, multiple same-name headers are sent as comma
* separated values.
*
* This breaks those headers into Link headers following the format
* http://tools.ietf.org/html/rfc2068#section-19.6.2.4
*/
while (preg_match('/^((?:[^"]|"[^"]*")*?),/', $header, $matches)) {
$header = trim(substr($header, strlen($matches[0])));
$links[] = $matches[1];
}
if ($header) {
$links[] = $header;
}
$requestMethod = $this->urlMatcher->getContext()->getMethod();
// Force the GET method to avoid the use of the
// previous method (LINK/UNLINK)
$this->urlMatcher->getContext()->setMethod('GET');
// The controller resolver needs a request to resolve the controller.
$stubRequest = new Request();
foreach ($links as $idx => $link) {
$linkHeader = $this->parseLinkHeader($link);
$resource = $this->parseResource($linkHeader, $event->getRequest());
try {
$route = $this->urlMatcher->match($resource);
} catch (\Exception $e) {
// If we don't have a matching route we return
// the original Link header
continue;
}
$stubRequest->attributes->replace($route);
if (false === ($controller = $this->resolver->getController($stubRequest))) {
continue;
}
// Make sure @ParamConverter and some other annotations are called
$subEvent = new FilterControllerEvent($event->getKernel(), $controller, $stubRequest, HttpKernelInterface::SUB_REQUEST);
$event->getDispatcher()->dispatch(KernelEvents::CONTROLLER, $subEvent);
$controller = $subEvent->getController();
$arguments = $this->resolver->getArguments($stubRequest, $controller);
try {
$result = call_user_func_array($controller, $arguments);
$value = is_array($result) ? current($result) : $result;
if ($linkHeader->hasRel()) {
unset($links[$idx]);
$links[$linkHeader->getRel()][] = $value;
} else {
$links[$idx] = $value;
}
} catch (\Exception $e) {
continue;
}
}
$event->getRequest()->attributes->set('links', $links);
$this->urlMatcher->getContext()->setMethod($requestMethod);
}