4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Event;
14 use Symfony\Component\HttpKernel\HttpKernelInterface;
15 use Symfony\Component\HttpFoundation\Request;
18 * Allows filtering of a controller callable.
20 * You can call getController() to retrieve the current controller. With
21 * setController() you can set a new controller that is used in the processing
24 * Controllers should be callables.
26 * @author Bernhard Schussek <bschussek@gmail.com>
28 class FilterControllerEvent extends KernelEvent
31 * The current controller.
35 public function __construct(HttpKernelInterface $kernel, $controller, Request $request, $requestType)
37 parent::__construct($kernel, $request, $requestType);
39 $this->setController($controller);
43 * Returns the current controller.
47 public function getController()
49 return $this->controller;
53 * Sets a new controller.
55 * @param callable $controller
57 * @throws \LogicException
59 public function setController($controller)
61 // controller must be a callable
62 if (!is_callable($controller)) {
63 throw new \LogicException(sprintf('The controller must be a callable (%s given).', $this->varToString($controller)));
66 $this->controller = $controller;
69 private function varToString($var)
71 if (is_object($var)) {
72 return sprintf('Object(%s)', get_class($var));
77 foreach ($var as $k => $v) {
78 $a[] = sprintf('%s => %s', $k, $this->varToString($v));
81 return sprintf('Array(%s)', implode(', ', $a));
84 if (is_resource($var)) {
85 return sprintf('Resource(%s)', get_resource_type($var));
100 return (string) $var;