From 884a5b06fa2e300285a67885d0652d201c7a330a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 10:13:05 -0500 Subject: [feature/twig] Add set_style function to controller helper PHPBB3-11598 --- phpBB/includes/controller/helper.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/controller') diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 74410ddfd1..ec09757a5d 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -23,6 +23,12 @@ use Symfony\Component\HttpFoundation\Response; */ class phpbb_controller_helper { + /** + * Style object + * @var phpbb_style + */ + protected $style; + /** * Template object * @var phpbb_template @@ -50,19 +56,36 @@ class phpbb_controller_helper /** * Constructor * + * @param phpbb_style $style Style object * @param phpbb_template $template Template object * @param phpbb_user $user User object * @param string $phpbb_root_path phpBB root path * @param string $php_ext PHP extension */ - public function __construct(phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext) + public function __construct(phpbb_style $style, phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext) { + $this->style = $style; $this->template = $template; $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } + /** + * Set style location based on (current) user's chosen style. + * + * @param array $style_directories The directories to add style paths for + * E.g. array('ext/foo/bar/styles', 'styles') + * Default: array('styles') (phpBB's style directory) + * @return phpbb_controller_helper $this + */ + public function set_style($style_base_directory = array('styles')) + { + $this->style->set_style($style_base_directory); + + return $this; + } + /** * Automate setting up the page and creating the response object. * -- cgit v1.2.1 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') 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') 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') 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 13c356545465a457b8c55dd9638f89165bab6271 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 5 Jul 2013 12:11:59 -0500 Subject: [feature/twig] Remove style dependency for controller helper If a controller wants to use set_style, it can just use phpbb_style PHPBB3-11598 --- phpBB/includes/controller/helper.php | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) (limited to 'phpBB/includes/controller') diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index ec09757a5d..74410ddfd1 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -23,12 +23,6 @@ use Symfony\Component\HttpFoundation\Response; */ class phpbb_controller_helper { - /** - * Style object - * @var phpbb_style - */ - protected $style; - /** * Template object * @var phpbb_template @@ -56,36 +50,19 @@ class phpbb_controller_helper /** * Constructor * - * @param phpbb_style $style Style object * @param phpbb_template $template Template object * @param phpbb_user $user User object * @param string $phpbb_root_path phpBB root path * @param string $php_ext PHP extension */ - public function __construct(phpbb_style $style, phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext) + public function __construct(phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext) { - $this->style = $style; $this->template = $template; $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } - /** - * Set style location based on (current) user's chosen style. - * - * @param array $style_directories The directories to add style paths for - * E.g. array('ext/foo/bar/styles', 'styles') - * Default: array('styles') (phpBB's style directory) - * @return phpbb_controller_helper $this - */ - public function set_style($style_base_directory = array('styles')) - { - $this->style->set_style($style_base_directory); - - return $this; - } - /** * Automate setting up the page and creating the response object. * -- 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/exception.php | 24 ----- phpBB/includes/controller/helper.php | 139 ---------------------------- phpBB/includes/controller/provider.php | 82 ----------------- phpBB/includes/controller/resolver.php | 154 -------------------------------- 4 files changed, 399 deletions(-) delete mode 100644 phpBB/includes/controller/exception.php delete mode 100644 phpBB/includes/controller/helper.php delete mode 100644 phpBB/includes/controller/provider.php delete mode 100644 phpBB/includes/controller/resolver.php (limited to 'phpBB/includes/controller') diff --git a/phpBB/includes/controller/exception.php b/phpBB/includes/controller/exception.php deleted file mode 100644 index faa8b6b584..0000000000 --- a/phpBB/includes/controller/exception.php +++ /dev/null @@ -1,24 +0,0 @@ -template = $template; - $this->user = $user; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } - - /** - * Automate setting up the page and creating the response object. - * - * @param string $handle The template handle to render - * @param string $page_title The title of the page to output - * @param int $status_code The status code to be sent to the page header - * @return Response object containing rendered page - */ - public function render($template_file, $page_title = '', $status_code = 200) - { - page_header($page_title); - - $this->template->set_filenames(array( - 'body' => $template_file, - )); - - page_footer(true, false, false); - - return new Response($this->template->assign_display('body'), $status_code); - } - - /** - * Generate a URL - * - * @param string $route The route to travel - * @param mixed $params String or array of additional url parameters - * @param bool $is_amp Is url using & (true) or & (false) - * @param string $session_id Possibility to use a custom session id instead of the global one - * @return string The URL already passed through append_sid() - */ - public function url($route, $params = false, $is_amp = true, $session_id = false) - { - $route_params = ''; - if (($route_delim = strpos($route, '?')) !== false) - { - $route_params = substr($route, $route_delim); - $route = substr($route, 0, $route_delim); - } - - if (is_array($params) && !empty($params)) - { - $params = array_merge(array( - 'controller' => $route, - ), $params); - } - else if (is_string($params) && $params) - { - $params = 'controller=' . $route . (($is_amp) ? '&' : '&') . $params; - } - else - { - $params = array('controller' => $route); - } - - return append_sid($this->phpbb_root_path . 'app.' . $this->php_ext . $route_params, $params, $is_amp, $session_id); - } - - /** - * Output an error, effectively the same thing as trigger_error - * - * @param string $message The error message - * @param string $code The error code (e.g. 404, 500, 503, etc.) - * @return Response A Reponse instance - */ - public function error($message, $code = 500) - { - $this->template->assign_vars(array( - 'MESSAGE_TEXT' => $message, - 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), - )); - - return $this->render('message_body.html', $this->user->lang('INFORMATION'), $code); - } -} diff --git a/phpBB/includes/controller/provider.php b/phpBB/includes/controller/provider.php deleted file mode 100644 index b2a5b9f6b2..0000000000 --- a/phpBB/includes/controller/provider.php +++ /dev/null @@ -1,82 +0,0 @@ -routing_paths = $routing_paths; - } - - /** - * Locate paths containing routing files - * This sets an internal property but does not return the paths. - * - * @return The current instance of this object for method chaining - */ - public function import_paths_from_finder(phpbb_extension_finder $finder) - { - // We hardcode the path to the core config directory - // because the finder cannot find it - $this->routing_paths = array_merge(array('config'), array_map('dirname', array_keys($finder - ->directory('config') - ->prefix('routing') - ->suffix('yml') - ->find() - ))); - - return $this; - } - - /** - * Get a list of controllers and return it - * - * @param string $base_path Base path to prepend to file paths - * @return array Array of controllers and their route information - */ - public function find($base_path = '') - { - $routes = new RouteCollection; - foreach ($this->routing_paths as $path) - { - $loader = new YamlFileLoader(new FileLocator($base_path . $path)); - $routes->addCollection($loader->load('routing.yml')); - } - - return $routes; - } -} 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