From 2fb48d60f1b8ea111c766d6d9e7a3dde2b8a4e74 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 11:08:36 -0500 Subject: [feature/twig] Attempt to automatically set style dir for ext controllers Extension authors can change it themselves if necessary PHPBB3-11598 --- phpBB/includes/controller/resolver.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/controller/resolver.php') diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index ee469aa9c8..2c7d112748 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -37,16 +37,24 @@ class phpbb_controller_resolver implements ControllerResolverInterface */ protected $container; + /** + * phpbb_style object + * @var phpbb_style + */ + protected $style; + /** * Construct method * * @param phpbb_user $user User Object * @param ContainerInterface $container ContainerInterface object + * @param phpbb_style $style */ - public function __construct(phpbb_user $user, ContainerInterface $container) + public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_style $style) { $this->user = $user; $this->container = $container; + $this->style = $style; } /** @@ -80,6 +88,24 @@ class phpbb_controller_resolver implements ControllerResolverInterface $controller_object = $this->container->get($service); + /* + * If this is an extension controller, we'll try to automatically set + * the style paths for the extension (the ext author can change them + * if necessary). + */ + $controller_dir = explode('_', get_class($controller_object)); + + // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... + if ($controller_dir[1] === 'ext') + { + $controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles'; + + if (is_dir($controller_style_dir)) + { + $this->style->set_style(array($controller_style_dir, 'styles')); + } + } + return array($controller_object, $method); } -- cgit v1.2.1 From 1ce33c1ff62426d030731cca100c4119bcd5265d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 11:12:26 -0500 Subject: [feature/twig] Safety check for 2fb48d6 PHPBB3-11598 --- phpBB/includes/controller/resolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/controller/resolver.php') diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index 2c7d112748..e44aa14b55 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -96,7 +96,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface $controller_dir = explode('_', get_class($controller_object)); // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... - if ($controller_dir[1] === 'ext') + if (isset($controller_dir[3]) && $controller_dir[1] === 'ext') { $controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles'; -- cgit v1.2.1 From b7ede06835ba784b81365946f057adf75ae7592b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 11:16:44 -0500 Subject: [feature/twig] Make style dependency optional for resolver PHPBB3-11598 --- phpBB/includes/controller/resolver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/controller/resolver.php') diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index e44aa14b55..95dfc8da8e 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -50,7 +50,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface * @param ContainerInterface $container ContainerInterface object * @param phpbb_style $style */ - public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_style $style) + public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_style $style = null) { $this->user = $user; $this->container = $container; @@ -96,7 +96,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface $controller_dir = explode('_', get_class($controller_object)); // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... - if (isset($controller_dir[3]) && $controller_dir[1] === 'ext') + if (!is_null($this->style) && isset($controller_dir[3]) && $controller_dir[1] === 'ext') { $controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles'; -- cgit v1.2.1 From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- phpBB/includes/controller/resolver.php | 154 --------------------------------- 1 file changed, 154 deletions(-) delete mode 100644 phpBB/includes/controller/resolver.php (limited to 'phpBB/includes/controller/resolver.php') diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php deleted file mode 100644 index 95dfc8da8e..0000000000 --- a/phpBB/includes/controller/resolver.php +++ /dev/null @@ -1,154 +0,0 @@ -user = $user; - $this->container = $container; - $this->style = $style; - } - - /** - * Load a controller callable - * - * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object - * @return bool|Callable Callable or false - * @throws phpbb_controller_exception - */ - public function getController(Request $request) - { - $controller = $request->attributes->get('_controller'); - - if (!$controller) - { - throw new phpbb_controller_exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']); - } - - // Require a method name along with the service name - if (stripos($controller, ':') === false) - { - throw new phpbb_controller_exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); - } - - list($service, $method) = explode(':', $controller); - - if (!$this->container->has($service)) - { - throw new phpbb_controller_exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); - } - - $controller_object = $this->container->get($service); - - /* - * If this is an extension controller, we'll try to automatically set - * the style paths for the extension (the ext author can change them - * if necessary). - */ - $controller_dir = explode('_', get_class($controller_object)); - - // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... - if (!is_null($this->style) && isset($controller_dir[3]) && $controller_dir[1] === 'ext') - { - $controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles'; - - if (is_dir($controller_style_dir)) - { - $this->style->set_style(array($controller_style_dir, 'styles')); - } - } - - return array($controller_object, $method); - } - - /** - * Dependencies should be specified in the service definition and can be - * then accessed in __construct(). Arguments are sent through the URL path - * and should match the parameters of the method you are using as your - * controller. - * - * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object - * @param mixed $controller A callable (controller class, method) - * @return bool False - * @throws phpbb_controller_exception - */ - public function getArguments(Request $request, $controller) - { - // At this point, $controller contains the object and method name - list($object, $method) = $controller; - $mirror = new ReflectionMethod($object, $method); - - $arguments = array(); - $parameters = $mirror->getParameters(); - $attributes = $request->attributes->all(); - foreach ($parameters as $param) - { - if (array_key_exists($param->name, $attributes)) - { - $arguments[] = $attributes[$param->name]; - } - else if ($param->getClass() && $param->getClass()->isInstance($request)) - { - $arguments[] = $request; - } - else if ($param->isDefaultValueAvailable()) - { - $arguments[] = $param->getDefaultValue(); - } - else - { - throw new phpbb_controller_exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); - } - } - - return $arguments; - } -} -- cgit v1.2.1