本文整理匯總了PHP中Symfony\Component\EventDispatcher\Event::getParameter方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::getParameter方法的具體用法?PHP Event::getParameter怎麽用?PHP Event::getParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\EventDispatcher\Event
的用法示例。
在下文中一共展示了Event::getParameter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handle
public function handle(Event $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
return false;
}
$exception = $event->getParameter('exception');
if (null !== $this->logger) {
$this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));
} else {
error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
}
$class = $this->container->getParameter('exception_manager.class');
$logger = $this->container->has('logger.debug') ? $this->container->get('logger.debug') : null;
$attributes = array('_controller' => $this->controller, 'manager' => new $class($exception, $event->getParameter('request'), $logger));
$request = $event->getParameter('request')->duplicate(null, null, $attributes);
try {
$response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
} catch (\Exception $e) {
if (null !== $this->logger) {
$this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
}
return false;
}
$event->setReturnValue($response);
return true;
}
示例2: handle
public function handle(Event $event)
{
$request = $event->getParameter('request');
$master = HttpKernelInterface::MASTER_REQUEST === $event->getParameter('request_type');
$this->initializeSession($request, $master);
$this->initializeRequestAttributes($request, $master);
}
示例3: handle
public function handle(Event $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
return false;
}
$exception = $event->getParameter('exception');
$request = $event->getParameter('request');
if (null !== $this->logger) {
$this->logger->err(sprintf('%s: %s (uncaught exception)', get_class($exception), $exception->getMessage()));
} else {
error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
}
$logger = null !== $this->logger ? $this->logger->getDebugLogger() : null;
$attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $logger, 'format' => 0 === strncasecmp(PHP_SAPI, 'cli', 3) ? 'txt' : $request->getRequestFormat());
$request = $request->duplicate(null, null, $attributes);
try {
$response = $event->getSubject()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
} catch (\Exception $e) {
if (null !== $this->logger) {
$this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
}
// re-throw the exception as this is a catch-all
throw new \RuntimeException('Exception thrown when handling an exception.', 0, $e);
}
$event->setReturnValue($response);
return true;
}
示例4: filter
/**
* Filters the Response.
*
* @param Event $event An Event instance
* @param Response $response A Response instance
*/
public function filter(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type') || $response->headers->has('Content-Type')) {
return $response;
}
$request = $event->getParameter('request');
$format = $request->getRequestFormat();
if (null !== $format && ($mimeType = $request->getMimeType($format))) {
$response->headers->set('Content-Type', $mimeType);
}
return $response;
}
示例5: handle
public function handle(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
return $response;
}
$request = $event->getParameter('request');
if ('3' === substr($response->getStatusCode(), 0, 1) || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat() || $request->isXmlHttpRequest()) {
return $response;
}
$response->setContent($this->injectToolbar($request, $response));
return $response;
}
示例6: handleException
/**
* Handles security related exceptions.
*
* @param Event $event An Event instance
*/
public function handleException(Event $event)
{
$exception = $event->getParameter('exception');
$request = $event->getParameter('request');
if ($exception instanceof AuthenticationException) {
if (null !== $this->logger) {
$this->logger->info(sprintf('Authentication exception occurred; redirecting to authentication entry point (%s)', $exception->getMessage()));
}
try {
$response = $this->startAuthentication($request, $exception);
} catch (\Exception $e) {
$event->setParameter('exception', $e);
return;
}
} elseif ($exception instanceof AccessDeniedException) {
$token = $this->context->getToken();
if (null === $token || $token instanceof AnonymousToken) {
if (null !== $this->logger) {
$this->logger->info('Access denied (user is anonymous); redirecting to authentication entry point');
}
try {
$response = $this->startAuthentication($request, new InsufficientAuthenticationException('Full authentication is required to access this resource.', $token, 0, $exception));
} catch (\Exception $e) {
$event->setParameter('exception', $e);
return;
}
} else {
if (null !== $this->logger) {
$this->logger->info('Access is denied (and user is not anonymous)');
}
if (null === $this->errorPage) {
return;
}
$subRequest = Request::create($this->errorPage);
$subRequest->attributes->set(SecurityContext::ACCESS_DENIED_ERROR, $exception->getMessage());
try {
$response = $event->getSubject()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
} catch (\Exception $e) {
if (null !== $this->logger) {
$this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
}
$event->setParameter('exception', new \RuntimeException('Exception thrown when handling an exception.', 0, $e));
return;
}
$response->setStatusCode(403);
}
} else {
return;
}
$event->setReturnValue($response);
return true;
}
示例7: handleResponse
/**
* Handles the core.response event.
*
* @param Event $event An Event instance
*
* @return Response $response A Response instance
*/
public function handleResponse(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
return $response;
}
if (null !== $this->matcher && !$this->matcher->matches($event->getParameter('request'))) {
return $response;
}
if ($this->onlyException && null === $this->exception) {
return $response;
}
$this->profiler->collect($event->getParameter('request'), $response, $this->exception);
$this->exception = null;
return $response;
}
示例8: handle
/**
* Handles basic authentication.
*
* @param Event $event An Event instance
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
if (false === ($username = $request->server->get('PHP_AUTH_USER', false))) {
return;
}
if (null !== ($token = $this->securityContext->getToken())) {
if ($token->isImmutable()) {
return;
}
if ($token instanceof UsernamePasswordToken && $token->isAuthenticated() && (string) $token === $username) {
return;
}
}
if (null !== $this->logger) {
$this->logger->debug(sprintf('Basic Authentication Authorization header found for user "%s"', $username));
}
try {
$token = $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $request->server->get('PHP_AUTH_PW')));
$this->securityContext->setToken($token);
} catch (AuthenticationException $failed) {
$this->securityContext->setToken(null);
if (null !== $this->logger) {
$this->logger->debug(sprintf('Authentication request failed: %s', $failed->getMessage()));
}
if ($this->ignoreFailure) {
return;
}
$event->setReturnValue($this->authenticationEntryPoint->start($request, $failed));
return true;
}
}
示例9: handle
/**
* Handles X509 authentication.
*
* @param Event $event An Event instance
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
if (null !== $this->logger) {
$this->logger->debug(sprintf('Checking secure context token: %s', $this->securityContext->getToken()));
}
list($user, $credentials) = $this->getPreAuthenticatedData($request);
if (null !== ($token = $this->securityContext->getToken())) {
if ($token->isImmutable()) {
return;
}
if ($token instanceof PreAuthenticatedToken && $token->isAuthenticated() && (string) $token === $user) {
return;
}
}
if (null !== $this->logger) {
$this->logger->debug(sprintf('Trying to pre-authenticate user "%s"', $user));
}
try {
$token = $this->authenticationManager->authenticate(new PreAuthenticatedToken($user, $credentials));
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: handle
public function handle(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
return $response;
}
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
$response->setContent(sprintf('<html><head></head><body><h1>This Request redirects to<br /><a href="%s">%s</a>.</h1></body></html>', $response->headers->get('location'), $response->headers->get('location')));
$response->setStatusCode(200);
$response->headers->delete('Location');
}
$request = $event->getParameter('request');
if (!$response->headers->has('X-Debug-Token') || '3' === substr($response->getStatusCode(), 0, 1) || $response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html') || 'html' !== $request->getRequestFormat() || $request->isXmlHttpRequest()) {
return $response;
}
$this->injectToolbar($request, $response);
return $response;
}
示例11: handle
public function handle(Event $event, Response $response)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
return $response;
}
$this->profiler->collect($response);
return $response;
}
示例12: handle
/**
* Handles anonymous authentication.
*
* @param Event $event An Event instance
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
if (null !== $this->context->getToken()) {
return;
}
$this->context->setToken(new AnonymousToken($this->key, 'anon.', array()));
if (null !== $this->logger) {
$this->logger->debug(sprintf('Populated SecurityContext with an anonymous Token'));
}
}
示例13: resolve
public function resolve(Event $event)
{
$request = $event->getParameter('request');
if (HttpKernelInterface::MASTER_REQUEST === $event->getParameter('request_type')) {
// set the context even if the parsing does not need to be done
// to have correct link generation
$this->router->setContext(array('base_url' => $request->getBaseUrl(), 'method' => $request->getMethod(), 'host' => $request->getHost(), 'is_secure' => $request->isSecure()));
}
if ($request->attributes->has('_controller')) {
return;
}
if (false !== ($parameters = $this->router->match($request->getPathInfo()))) {
if (null !== $this->logger) {
$this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], str_replace("\n", '', var_export($parameters, true))));
}
$request->attributes->replace($parameters);
} elseif (null !== $this->logger) {
$this->logger->err(sprintf('No route found for %s', $request->getPathInfo()));
}
}
示例14: handle
/**
* Handles security.
*
* @param Event $event An Event instance
*/
public function handle(Event $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getParameter('request_type')) {
return;
}
$request = $event->getParameter('request');
$this->dispatcher->disconnect('core.security');
list($listeners, $exception) = $this->map->getListeners($request);
if (null !== $exception) {
$exception->register($this->dispatcher);
}
foreach ($listeners as $listener) {
$listener->register($this->dispatcher);
}
$e = $this->dispatcher->notifyUntil(new Event($request, 'core.security', array('request' => $request)));
if ($e->isProcessed()) {
$event->setReturnValue($e->getReturnValue());
return true;
}
return;
}
示例15: handle
/**
*
*
* @param Event $event An Event instance
*/
public function handle(Event $event)
{
$request = $event->getParameter('request');
if ($this->logoutPath !== $request->getPathInfo()) {
return;
}
$this->securityContext->setToken(null);
$request->getSession()->invalidate();
$response = new Response();
$response->setRedirect(0 !== strpos($this->targetUrl, 'http') ? $request->getUriForPath($this->targetUrl) : $this->targetUrl, 302);
$event->setReturnValue($response);
return true;
}