本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\FilterControllerEvent类的典型用法代码示例。如果您正苦于以下问题:PHP FilterControllerEvent类的具体用法?PHP FilterControllerEvent怎么用?PHP FilterControllerEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FilterControllerEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onKernelController
/**
* Handles the @Njax() annotation for the found controller action.
*
* @param FilterControllerEvent $event Event called.
*/
public function onKernelController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
}
$request = $event->getRequest();
$njax = $this->container->get('njax');
// force @Njax() annotation for *all* NJAX requests
if (!($njaxConfiguration = $request->attributes->get('_njax'))) {
if (!$njax->isNjax()) {
return;
}
$njaxConfiguration = new NjaxAnnotation(array());
$request->attributes->set('_njax', $njaxConfiguration);
}
// force every @Njax() annotation to also trigger @Template() (if not defined)
if (!($templateConfiguration = $request->attributes->get('_template'))) {
$templateAnnotation = new Template(array());
// if there is @Njax default template set then use this
if ($njaxConfiguration->getDefaultTemplate()) {
$templateConfiguration = $njaxConfiguration->getDefaultTemplate();
} else {
// if not, then try to guess the template name (just like @Template() would do)
$guesser = $this->container->get('sensio_framework_extra.view.guesser');
$templateConfiguration = $guesser->guessTemplateName($controller, $request);
}
$request->attributes->set('_template', $templateConfiguration);
}
if (!$njaxConfiguration->getDefaultTemplate()) {
$njaxConfiguration->setDefaultTemplate($templateConfiguration);
}
}
示例2: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
$request = $event->getRequest();
$annotation = $this->findAnnotation($controller);
if (!$annotation) {
return;
}
$lastTouched = $annotation->calculateLastModified($this->metaQueryFactory);
if (!$lastTouched) {
return;
}
$this->lastTouchedResults[$request] = $lastTouched;
/*
* Für kernel.debug = 1 senden wir niemals
* 304-Responses, anstatt den Kernel auszuführen:
*
* Das Ergebnis hängt auch von vielen Dingen außerhalb
* wfd_meta ab (z. B. template-Code), die wir hier nicht
* berücksichtigen können.
*/
if ($this->debug) {
return;
}
$response = new Response();
$response->setLastModified($lastTouched);
if ($response->isNotModified($request)) {
$event->setController(function () use($response) {
return $response;
});
}
}
示例3: onKernelController
/**
* Mark request with flag if handled with rest controller
*
* @param FilterControllerEvent $event
*/
public function onKernelController(FilterControllerEvent $event)
{
$callable = $event->getController();
if (is_array($callable) && count($callable) === 2 && $callable[0] instanceof RestController) {
$event->getRequest()->attributes->set('__is_rest', true);
}
}
示例4: getCalledMethod
/**
* Creates the method needed from the class- and method name
*
* @param FilterControllerEvent $event
*
* @return \ReflectionMethod
*/
private function getCalledMethod(FilterControllerEvent $event)
{
list($object, $method) = $event->getController();
$className = get_class($object);
$reflectionClass = new \ReflectionClass($className);
return $reflectionClass->getMethod($method);
}
示例5: onKernelController
/**
* http://api.symfony.com/2.4/Symfony/Component/HttpKernel/Event/FilterControllerEvent.html
*
* @param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
* @return type
*/
public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
// Request object
$seesion = $request->getSession();
$container = $this->container;
if (!is_array($controller = $event->getController())) {
return;
}
//if ($request->get('id') || $request->get('keyword')) {
$entity = new Tracking();
$entity->setController(get_class($controller[0]));
// controller Formation\Bundle\Controller\PageController
$entity->setAction($controller[1]);
// getNextPageAction getPreviousPageAction
$entity->setHttpMethod($request->getMethod());
$entity->setIpRequest($request->getClientIp());
$entity->setIdRequest($request->get('id'));
$entity->setLang($seesion->get('_locale'));
$entity->setPageRequest($request->get('page'));
$entity->setKeywordRequest($request->get('keyword'));
$entity->setUriRequest($request->getUri());
$entity->setQueryRequest($request->getQueryString());
$entity->setPathInfo($request->getPathInfo());
$date = new \DateTime('now');
$entity->setCreated($date);
$em = $container->get('doctrine')->getManager();
if ($container->get('security.context')->getToken() && $container->get('security.context')->getToken()->getUser()) {
if (is_object($container->get('security.context')->getToken()->getUser())) {
$user_id = $container->get('security.context')->getToken()->getUser()->getId();
$user = $em->getRepository('UserBundle:User')->find($user_id);
$entity->setUser($user);
$last_acces = $em->getRepository('TrackingBundle:Tracking')->getLastAccess($user_id);
// update last access duration
if (is_object($last_acces)) {
//exit(\Doctrine\Common\Util\Debug::dump($last_acces->getCreated()));
$now = new \DateTime('now');
$diff = $now->getTimestamp() - $last_acces->getCreated()->getTimestamp();
$interval = new \DateTime();
$interval->setTimestamp($diff);
$tracking_id = $last_acces->getId();
$tracking = $em->getRepository('TrackingBundle:Tracking')->find($tracking_id);
$tracking->setDuration($interval);
//exit(\Doctrine\Common\Util\Debug::dump(strtotime($last_acces->getCreated()->format("Y-m-d H:i:s"))));
//$em->flush();
}
// update formation progression
// case 1 : Formation\Bundle\Controller\ChapterController && action=showAction && id_request
// get total formation page, get fos_user_formation percent, update percent
// case 2 : Formation\Bundle\Controller\PageController && action=getNextPageAction or action=getPreviousPageAction && id_request
// get total formation page
}
}
$em->persist($entity);
$em->flush();
//var_dump($last_acces->getCreated());
//var_dump($now);
//exit(\Doctrine\Common\Util\Debug::dump($interval));
//}
}
示例6: onKernelController
/**
* Determines and sets the Request format
*
* @param GetResponseEvent $event The event
*/
public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
/*
// TODO get priorities from the controller action
$action = $request->attributes->get('_controller');
$controller = $event->getController();
$priorities =
*/
if (empty($priorities)) {
$priorities = $this->defaultPriorities;
}
$format = null;
if (!empty($priorities)) {
$format = $this->formatNegotiator->getBestFormat($request, $priorities, $this->preferExtension);
}
if (null === $format) {
$format = $this->fallbackFormat;
}
if (null === $format) {
if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
throw new HttpException(Codes::HTTP_NOT_ACCEPTABLE, "No matching accepted Response format could be determined");
}
return;
}
$request->setRequestFormat($format);
}
示例7: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
if (isset($controller[0]) && is_object($controller[0])) {
$controller[0]->preAction();
}
}
示例8: onCoreController
/**
* Modifies the ParamConverterManager instance.
*
* @param FilterControllerEvent $event A FilterControllerEvent instance
*/
public function onCoreController(FilterControllerEvent $event)
{
$controller = $event->getController();
$request = $event->getRequest();
$configurations = array();
if ($configuration = $request->attributes->get('_converters')) {
$configurations = is_array($configuration) ? $configuration : array($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() && !$request->attributes->get($param->getName())) {
$configuration = new ParamConverter(array());
$configuration->setName($param->getName());
$configuration->setClass($param->getClass()->getName());
$configuration->setIsOptional($param->isOptional());
$configurations[] = $configuration;
}
}
$this->manager->apply($request, $configurations);
}
示例9: onKernelController
/**
* Modifies the Request object to apply configuration information found in
* controllers annotations like the template to render or HTTP caching
* configuration.
*
* @param FilterControllerEvent $event A FilterControllerEvent instance
*
* @return void
*/
public function onKernelController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
}
$className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
$object = new \ReflectionClass($className);
$transactional = $this->reader->getClassAnnotation($object, Transactional::NAME);
if (!$transactional instanceof Transactional) {
return;
}
$avoidTransaction = $this->reader->getMethodAnnotation($object->getMethod($controller[1]), AvoidTransaction::NAME);
if (!is_null($avoidTransaction)) {
return;
}
$request = $event->getRequest();
$modelName = $transactional->model;
$model = new $modelName();
$this->transactionBuilder->setRequestMethod($request->getRealMethod());
$this->transactionBuilder->setRequestSource(Transaction::SOURCE_REST);
$this->transactionBuilder->setRelatedRoute($transactional->relatedRoute);
$ids = [];
foreach ($model->getIds() as $field => $value) {
$ids[$field] = $request->attributes->get($field);
}
$this->transactionBuilder->setRelatedIds($ids);
$this->transactionBuilder->setModel($transactional->model);
$transaction = $this->transactionBuilder->build();
$request->attributes->set('transaction', $transaction);
}
示例10: onKernelController
/**
* Guesses the template name to render and its variables and adds them to
* the request object.
*
* @param FilterControllerEvent $event A FilterControllerEvent instance
*/
public function onKernelController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
}
$request = $event->getRequest();
if (!($configuration = $request->attributes->get('_template'))) {
return;
}
if (!$configuration->getTemplate()) {
$guesser = $this->container->get('sensio_framework_extra.view.guesser');
$configuration->setTemplate($guesser->guessTemplateName($controller, $request, $configuration->getEngine()));
}
$request->attributes->set('_template', $configuration->getTemplate());
$request->attributes->set('_template_vars', $configuration->getVars());
$request->attributes->set('_template_streamable', $configuration->isStreamable());
// all controller method arguments
if (!$configuration->getVars()) {
$r = new \ReflectionObject($controller[0]);
$vars = array();
foreach ($r->getMethod($controller[1])->getParameters() as $param) {
$vars[] = $param->getName();
}
$request->attributes->set('_template_default_vars', $vars);
}
}
示例11: 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);
}
示例12: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
// admin menu will be rendered only when HttpKernelInterface::MASTER_REQUEST
if ($event->getRequestType() == HttpKernelInterface::SUB_REQUEST) {
return;
}
if (!$this->container->get('session')->has('admin/menu')) {
$builder = new AdminMenuBuilder();
$builder->add(new AdminMenuItem(['id' => 'dashboard', 'class' => 'dashboard', 'name' => $this->translator->trans('Dashboard'), 'path' => '[menu][dashboard]', 'sort_order' => 10]));
$builder->add(new AdminMenuItem(['id' => 'catalog', 'class' => 'catalog', 'name' => $this->translator->trans('Catalog'), 'path' => '[menu][catalog]', 'sort_order' => 20]));
$builder->add(new AdminMenuItem(['id' => 'promotions', 'class' => 'promotions', 'name' => $this->translator->trans('Promotions'), 'path' => '[menu][promotions]', 'sort_order' => 30]));
$builder->add(new AdminMenuItem(['id' => 'sales', 'class' => 'sales', 'name' => $this->translator->trans('Sales'), 'path' => '[menu][sales]', 'sort_order' => 40]));
$builder->add(new AdminMenuItem(['id' => 'reports', 'class' => 'reports', 'name' => $this->translator->trans('Reports'), 'path' => '[menu][reports]', 'sort_order' => 50]));
$builder->add(new AdminMenuItem(['id' => 'crm', 'class' => 'crm', 'name' => $this->translator->trans('CRM'), 'link' => '', 'path' => '[menu][crm]', 'sort_order' => 60]));
$builder->add(new AdminMenuItem(['id' => 'cms', 'class' => 'cms', 'name' => $this->translator->trans('CMS'), 'path' => '[menu][cms]', 'sort_order' => 70]));
$builder->add(new AdminMenuItem(['id' => 'layout', 'class' => 'layout', 'name' => $this->translator->trans('Layout settings'), 'path' => '[menu][layout]', 'sort_order' => 80]));
$builder->add(new AdminMenuItem(['id' => 'integration', 'class' => 'integration', 'name' => $this->translator->trans('Integration'), 'path' => '[menu][integration]', 'sort_order' => 90]));
$builder->add(new AdminMenuItem(['id' => 'configuration', 'class' => 'configuration', 'name' => $this->translator->trans('Configuration'), 'link' => '', 'path' => '[menu][configuration]', 'sort_order' => 100]));
$builder->add(new AdminMenuItem(['id' => 'localization', 'class' => 'localization', 'name' => $this->translator->trans('Localization'), 'path' => '[menu][configuration][localization]', 'sort_order' => 10]));
$builder->add(new AdminMenuItem(['id' => 'store_management', 'class' => 'store_management', 'name' => $this->translator->trans('Store management'), 'path' => '[menu][configuration][store_management]', 'sort_order' => 20]));
$builder->add(new AdminMenuItem(['id' => 'user_management', 'name' => $this->translator->trans('User management'), 'path' => '[menu][configuration][user_management]', 'sort_order' => 30]));
$adminMenuEvent = new AdminMenuInitEvent($builder);
$event->getDispatcher()->dispatch(AdminMenuInitEvent::ADMIN_MENU_INIT_EVENT, $adminMenuEvent);
$menu = $adminMenuEvent->getBuilder()->getMenu();
$this->container->get('session')->set('admin/menu', $menu);
}
}
示例13: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
if (!$this->isTrackingEnabled) {
return;
}
$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
* @link http://symfony.com/doc/current/event_dispatcher/before_after_filters.html#creating-an-event-listener
*/
if (!is_array($controller)) {
return;
}
$controller = $controller[0];
if ($controller instanceof Controller) {
$request = $event->getRequest();
$path = $request->getRequestUri();
$host = $request->getHost();
$title = get_class($controller);
$data = ['dh' => $host, 'dp' => $path, 'dt' => $title];
try {
$this->tracker->send($data, 'pageview');
} catch (\Exception $e) {
$this->logger->error('Failed to send tracking data.', ['exception' => $e]);
}
}
}
示例14: onKernelController
/**
* Core controller handler.
*
* @param FilterControllerEvent $event
*
* @throws \InvalidArgumentException
*/
public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
return;
}
$paramFetcher = $this->container->get('fos_rest.request.param_fetcher');
$controller = $event->getController();
if (is_callable($controller) && method_exists($controller, '__invoke')) {
$controller = [$controller, '__invoke'];
}
$paramFetcher->setController($controller);
$attributeName = $this->getAttributeName($controller);
$request->attributes->set($attributeName, $paramFetcher);
if ($this->setParamsAsAttributes) {
$params = $paramFetcher->all();
foreach ($params as $name => $param) {
if ($request->attributes->has($name) && null !== $request->attributes->get($name)) {
$msg = sprintf("ParamFetcher parameter conflicts with a path parameter '{$name}' for route '%s'", $request->attributes->get('_route'));
throw new \InvalidArgumentException($msg);
}
$request->attributes->set($name, $param);
}
}
}
示例15: onKernelController
/**
* Handles HTTP validation headers.
*/
public function onKernelController(FilterControllerEvent $event)
{
$request = $event->getRequest();
if (!($configuration = $request->attributes->get('_cache'))) {
return;
}
$response = new Response();
$lastModifiedDate = '';
if ($configuration->getLastModified()) {
$lastModifiedDate = $this->getExpressionLanguage()->evaluate($configuration->getLastModified(), $request->attributes->all());
$response->setLastModified($lastModifiedDate);
}
$etag = '';
if ($configuration->getETag()) {
$etag = hash('sha256', $this->getExpressionLanguage()->evaluate($configuration->getETag(), $request->attributes->all()));
$response->setETag($etag);
}
if ($response->isNotModified($request)) {
$event->setController(function () use($response) {
return $response;
});
} else {
if ($etag) {
$this->etags[$request] = $etag;
}
if ($lastModifiedDate) {
$this->lastModifiedDates[$request] = $lastModifiedDate;
}
}
}