本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\FilterControllerEvent::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP FilterControllerEvent::getRequest方法的具体用法?PHP FilterControllerEvent::getRequest怎么用?PHP FilterControllerEvent::getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Event\FilterControllerEvent
的用法示例。
在下文中一共展示了FilterControllerEvent::getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelController
public function onKernelController(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event)
{
if ($event->getRequestType() == \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST) {
return;
}
if ($event->getRequest()->isXmlHttpRequest()) {
return;
}
if (null == $this->security->getToken()) {
return;
}
$this->user = $this->security->getToken()->getUser();
if ($this->security->isGranted('ROLE_ADMIN')) {
return;
}
$controller = $event->getController();
if (!preg_match('#FrontBundle#', get_class($controller[0]))) {
return;
}
$this->request = $event->getRequest();
$this->trueSession = $this->request->getSession();
$this->route = $this->request->get('_route');
$this->routeParams = $this->request->get('_route_params');
if (preg_match('#admin#', $this->route) || preg_match('#tracking#', $this->route) || preg_match('#_wdt#', $this->route)) {
return;
}
$this->initSession();
$this->initView();
}
示例2: onControllerMatched
/**
* After a controller has been matched. We need to inject current
* Kernel instance and main DI container.
*
* @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
*/
public function onControllerMatched(FilterControllerEvent $event)
{
$matchedCtrl = $event->getController()[0];
/*
* Inject current Kernel to the matched Controller
*/
if ($matchedCtrl instanceof Controller) {
$matchedCtrl->setKernel($this->kernel);
$matchedCtrl->setContainer($this->kernel->getContainer());
}
/*
* Do not inject current theme when
* Install mode is active.
*/
if (true !== $this->kernel->container['config']['install'] && $event->getRequest() instanceof RoadizRequest) {
// No node controller matching in install mode
$event->getRequest()->setTheme($matchedCtrl->getTheme());
}
/*
* Set request locale if _locale param
* is present in Route.
*/
$routeParams = $event->getRequest()->get('_route_params');
if (!empty($routeParams["_locale"])) {
$event->getRequest()->setLocale($routeParams["_locale"]);
}
/*
* Prepare base assignation
*/
if ($matchedCtrl instanceof AppController) {
$matchedCtrl->__init();
}
}
示例3: onCoreController
public function onCoreController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
}
$method = new \ReflectionMethod($controller[0], $controller[1]);
if (!($annotations = $this->reader->getMethodAnnotations($method))) {
return;
}
foreach ($annotations as $annotation) {
if ($annotation instanceof LayoutAnnotation) {
if ($annotation->getPosition()) {
$root = $this->em->getRepository('TemplateDesignerLayoutBundle:Layout')->findLayoutWitOptions($annotation->getName(), $annotation->getPosition());
} else {
$root = $this->em->getRepository('TemplateDesignerLayoutBundle:Layout')->findOneBy(array('name' => $annotation->getName()));
}
if (!$annotation->getPosition() && !$annotation->getName()) {
throw new \Exception("Parameter missing in layout annotation", 1);
}
if (!$root) {
throw new NotFoundHttpException('Layout not found');
}
$route_params = $event->getRequest()->attributes->get('_route_params');
$route_params['rootLayout'] = $root;
$event->getRequest()->attributes->set('_route_params', $route_params);
}
}
}
示例4: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
/*
* $controller passed can be either a class or a Closure.
* This is not usual in Symfony but it may happen.
* If it is a class, it comes in array format
*/
if (!is_array($controller)) {
return;
}
if ($controller[0] instanceof TokenAuthenticatedController) {
$this->session = $this->container->get('session');
$custom = json_decode($this->session->get('custom'));
if (!$custom) {
return;
}
$custom = $this->em->find('WoojinOrderBundle:Custom', $custom->id);
if ($custom->getCsrf() !== $this->session->get('avenue_token')) {
$this->session->clear();
$url = $this->container->get('router')->generate('front_custom_login', null, true);
throw new AccessDeniedHttpException('憑證失效,請前往' . $url . '重新登入會員');
}
// mark the request as having passed token authentication
$event->getRequest()->attributes->set('auth_token', true);
} else {
$event->getRequest()->attributes->set('auth_token', null);
}
}
示例5: apiFirewall
public function apiFirewall(FilterControllerEvent $event)
{
$controller = $event->getController();
if ($controller[0] instanceof BaseApiController && $event->getRequest()->attributes->get('not-logged') != 1) {
$apiAccount = $this->checkApiAccess($event->getRequest());
$controller[0]->setApiUser($apiAccount);
}
}
示例6: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$this->controllers[$event->getRequest()] = $event->getController();
if ($parentRequestAttributes = $event->getRequest()->attributes->get('_forwarded')) {
if ($parentRequestAttributes instanceof ParameterBag) {
$parentRequestAttributes->set('_forward_controller', $event->getController());
}
}
}
示例7: onCoreController
/**
* On each request we want to update the user's last activity datetime
*
* @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
* @return void
*/
public function onCoreController(FilterControllerEvent $event)
{
if (true === isset($this->context) && true === is_object($this->context)) {
if (true === is_object($this->context->getToken()) && $this->context->getToken() != null) {
$user = $this->context->getToken()->getUser();
}
}
if (false === isset($user) || false === is_object($user) || $user == null) {
$user = null;
}
$route = $event->getRequest()->attributes->get('_route');
$request = $event->getRequest();
$session = $request->getSession();
$routeParams = $request->get('_route_params');
if ($route[0] == '_') {
return;
}
$routeData = ['name' => $route, 'params' => $routeParams];
$thisRoute = $session->get('this_route', []);
if (true === isset($_SERVER["REQUEST_URI"]) && trim($_SERVER["REQUEST_URI"]) != "") {
if (true === isset($_COOKIE['LICO_URL_2']) && trim($_COOKIE['LICO_URL_2']) != "") {
setcookie('LICO_URL_3', urldecode(trim($_COOKIE['LICO_URL_2'])), time() + 3600, '/');
}
if (true === isset($_COOKIE['LICO_URL_1']) && trim($_COOKIE['LICO_URL_1']) != "") {
setcookie('LICO_URL_2', urldecode(trim($_COOKIE['LICO_URL_1'])), time() + 3600, '/');
}
if (true === isset($_COOKIE['LICO_URL_0']) && trim($_COOKIE['LICO_URL_0']) != "") {
setcookie('LICO_URL_1', urldecode(trim($_COOKIE['LICO_URL_0'])), time() + 3600, '/');
}
setcookie('LICO_URL_0', $_SERVER["REQUEST_URI"], time() + 3600, '/');
}
$session->set('last_route', $thisRoute);
$session->set('this_route', $routeData);
if ($route == null || true === in_array($route, array('_wdt'))) {
return true;
}
$ipaddress = $this->container->get('request')->server->get("REMOTE_ADDR");
if ($ipaddress == "127.0.0.1") {
if (true === isset($_SERVER["REMOTE_ADDR"]) && trim($_SERVER["REMOTE_ADDR"]) != "") {
$ipaddress = $_SERVER["REMOTE_ADDR"];
} else {
$ipaddress = "N/A";
}
}
$useragent = $this->container->get('request')->server->get("HTTP_USER_AGENT");
$obj = new DetectBotFromUserAgent();
$isbot = $obj->licoIsBot($useragent, $ipaddress);
$activity = new Activity();
$activity->setUser($user);
$activity->setRoute($route);
$activity->setIpAddress($ipaddress);
$activity->setUserAgent($useragent);
$activity->setIsBot($isbot);
$activity->setCreatedAt(new \DateTime());
$this->em->persist($activity);
$this->em->flush();
}
示例8: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
if ($controller[0] instanceof ApiController) {
$controller[0]->initialize($event->getRequest());
$controller[0]->checkApiKey($event->getRequest());
}
}
示例9: onResourceIfAllowedAnnotationMethod
/**
* Listens when the annotation exists loading the resource of id given and if it is allowed.
*
* @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event The filter controller event
*/
public function onResourceIfAllowedAnnotationMethod(FilterControllerEvent $event)
{
list($object, $method) = $event->getController();
$reflectionClass = new \ReflectionClass(get_class($object));
$reflectionMethod = $reflectionClass->getMethod($method);
if ($annotation = $this->annotationReader->getMethodAnnotation($reflectionMethod, $this->annotationClass)) {
$resourceId = $event->getRequest()->attributes->get(sprintf('%sId', $this->resource));
if (null !== $resourceId) {
$event->getRequest()->attributes->set($this->resource, $this->getResourceIfAllowed($resourceId, $annotation->getGrant()));
}
}
}
示例10: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$controllers = $event->getController();
if (is_array($controllers)) {
$controller = $controllers[0];
if (is_object($controller) && method_exists($controller, 'preExecute') && $event->getRequest()->getMethod() != 'OPTIONS') {
$controller->preExecute($event->getRequest());
}
}
}
}
示例11: onKernelController
/**
* Handle actions before the kernel loads the controller.
*
* @param FilterControllerEvent $event
*/
public function onKernelController(FilterControllerEvent $event)
{
if (null === ($module = $event->getRequest()->get('module'))) {
return;
}
if (!$module instanceof ModuleInterface) {
try {
$module = $this->getModularRouter()->getModuleByRequest($event->getRequest());
} catch (Exception $e) {
return;
}
}
$this->getModuleManager()->setCurrentModule($module);
}
示例12: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
if (!is_array($controller) || !$controller[0] instanceof RestController) {
return;
}
$action = $controller[1];
$controller = $controller[0];
$reflection = new \ReflectionObject($controller);
$reader = new AnnotationReader();
$authorize = $reader->getClassAnnotation($reflection, Authorize::class);
$methodAuthorize = $reader->getMethodAnnotation($reflection->getMethod($action), Authorize::class);
if ($methodAuthorize != null) {
$authorize = $methodAuthorize;
}
$config = $this->container->getParameter("rest.config")["authentication"];
if ($authorize != null && $config["enabled"]) {
$authHeader = $event->getRequest()->headers->get("authorization", "null null");
$explode = explode(" ", $authHeader);
$type = $explode[0];
$token = $explode[1];
if ($authHeader == "null null") {
$this->unauth();
}
if (strtolower($type) != "bearer") {
$this->unauth();
}
$type = $config["oauth_type"];
if ($type == "own") {
/** @var OAuthService $oauthService */
$oauthService = $this->container->get("rest.oauth_service");
$authToken = $oauthService->getAuthToken($token);
if ($authToken == null) {
$this->unauth();
}
$session = new Session(new MockArraySessionStorage());
$session->set("token", $authToken);
$session->set("consumer", $authToken->getConsumer());
$session->set("user", $authToken->getUser());
$event->getRequest()->setSession($session);
} else {
if ($type == "static") {
$tokens = $config["oauth"]["static_tokens"];
if (!in_array($token, $tokens)) {
$this->unauth();
}
}
}
}
}
示例13: onKernelController
/**
* Searches for sluggable objects in the route parameters and checks slugs if necessary.
*
* If an invalid slug is detected, then the user will be redirected to the URLs with the valid slug.
*
* @param FilterControllerEvent $event
*/
public function onKernelController(FilterControllerEvent $event)
{
$attributes = $event->getRequest()->attributes;
foreach ($attributes as $name => $value) {
if ($this->hasValidSlug($attributes, $name)) {
continue;
}
$event->stopPropagation();
// Invalid slug passed. Redirect to a URL with valid slug.
$event->setController(function () use($event, $name) {
return $this->createRedirectFor($event->getRequest(), $name);
});
break;
}
}
示例14: onKernelController
/**
* @param FilterControllerEvent $event
*/
public function onKernelController(FilterControllerEvent $event)
{
if (HttpKernel::MASTER_REQUEST == $event->getRequestType()) {
$this->linkProvider->setRequest($event->getRequest());
}
return;
}
示例15: onKernelController
/**
* Modifies the ParamConverterManager instance.
*
* @param FilterControllerEvent $event A FilterControllerEvent instance
*/
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
$request = $event->getRequest();
$configurations = array();
if ($configuration = $request->attributes->get('_converters')) {
foreach (is_array($configuration) ? $configuration : array($configuration) as $configuration) {
$configurations[$configuration->getName()] = $configuration;
}
}
if (is_array($controller)) {
$r = new \ReflectionMethod($controller[0], $controller[1]);
} else {
$r = new \ReflectionFunction($controller);
}
// automatically apply conversion for non-configured objects
foreach ($r->getParameters() as $param) {
if (!$param->getClass() || $param->getClass()->isInstance($request)) {
continue;
}
$name = $param->getName();
if (!isset($configurations[$name])) {
$configuration = new ParamConverter(array());
$configuration->setName($name);
$configuration->setClass($param->getClass()->getName());
$configurations[$name] = $configuration;
} elseif (null === $configurations[$name]->getClass()) {
$configurations[$name]->setClass($param->getClass()->getName());
}
$configurations[$name]->setIsOptional($param->isOptional());
}
$this->manager->apply($request, $configurations);
}