diff options
Diffstat (limited to 'phpBB/phpbb/controller')
-rw-r--r-- | phpBB/phpbb/controller/exception.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/controller/helper.php | 52 | ||||
-rw-r--r-- | phpBB/phpbb/controller/provider.php | 71 | ||||
-rw-r--r-- | phpBB/phpbb/controller/resolver.php | 8 |
4 files changed, 65 insertions, 74 deletions
diff --git a/phpBB/phpbb/controller/exception.php b/phpBB/phpbb/controller/exception.php index e8694b8bcf..06ece8d1d5 100644 --- a/phpBB/phpbb/controller/exception.php +++ b/phpBB/phpbb/controller/exception.php @@ -10,14 +10,6 @@ namespace phpbb\controller; /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** * Controller exception class * @package phpBB3 */ diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php index 07483a91eb..54c30c93fc 100644 --- a/phpBB/phpbb/controller/helper.php +++ b/phpBB/phpbb/controller/helper.php @@ -9,15 +9,9 @@ namespace phpbb\controller; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Generator\UrlGenerator; +use Symfony\Component\Routing\RequestContext; /** * Controller helper class, contains methods that do things for controllers @@ -59,18 +53,20 @@ class helper * Constructor * * @param \phpbb\template\template $template Template object - * @param \phpbb\user $user User object - * @param \phpbb\config\config $config Config object + * @param \phpbb\user $user User object + * @param \phpbb\config\config $config Config object + * @param \phpbb\controller\provider $provider Path provider * @param string $phpbb_root_path phpBB root path * @param string $php_ext PHP extension */ - public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, $phpbb_root_path, $php_ext) + public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, $phpbb_root_path, $php_ext) { $this->template = $template; $this->user = $user; $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->route_collection = $provider->get_routes(); } /** @@ -81,9 +77,9 @@ class helper * @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) + public function render($template_file, $page_title = '', $status_code = 200, $display_online_list = false) { - page_header($page_title); + page_header($page_title, $display_online_list); $this->template->set_filenames(array( 'body' => $template_file, @@ -95,21 +91,33 @@ class helper } /** - * Generate a URL + * Generate a URL to a route * - * @param string $route The route to travel - * @param mixed $params String or array of additional url parameters + * @param string $route Name of the route to travel + * @param array $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) + public function route($route, array $params = array(), $is_amp = true, $session_id = false) { - $route_params = ''; - if (($route_delim = strpos($route, '?')) !== false) + $anchor = ''; + if (isset($params['#'])) + { + $anchor = '#' . $params['#']; + unset($params['#']); + } + $url_generator = new UrlGenerator($this->route_collection, new RequestContext()); + $route_url = $url_generator->generate($route, $params); + + if (strpos($route_url, '/') === 0) + { + $route_url = substr($route_url, 1); + } + + if ($is_amp) { - $route_params = substr($route, $route_delim); - $route = substr($route, 0, $route_delim); + $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url); } // If enable_mod_rewrite is false, we need to include app.php @@ -119,7 +127,7 @@ class helper $route_prefix .= 'app.' . $this->php_ext . '/'; } - return append_sid($route_prefix . "$route" . $route_params, $params, $is_amp, $session_id); + return append_sid($route_prefix . $route_url . $anchor, false, $is_amp, $session_id); } /** diff --git a/phpBB/phpbb/controller/provider.php b/phpBB/phpbb/controller/provider.php index 3aad08e3aa..9df8130210 100644 --- a/phpBB/phpbb/controller/provider.php +++ b/phpBB/phpbb/controller/provider.php @@ -9,14 +9,6 @@ namespace phpbb\controller; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Loader\YamlFileLoader; use Symfony\Component\Config\FileLocator; @@ -31,54 +23,61 @@ class provider * YAML file(s) containing route information * @var array */ - protected $routing_paths; + protected $routing_files; + + /** + * Collection of the routes in phpBB and all found extensions + * @var RouteCollection + */ + protected $routes; /** * Construct method * - * @param array() $routing_paths Array of strings containing paths + * @param array() $routing_files Array of strings containing paths * to YAML files holding route information */ - public function __construct($routing_paths = array()) + public function __construct(\phpbb\extension\finder $finder = null, $routing_files = array()) { - $this->routing_paths = $routing_paths; + $this->routing_files = $routing_files; + + if ($finder) + { + // We hardcode the path to the core config directory + // because the finder cannot find it + $this->routing_files = array_merge($this->routing_files, array('config/routing.yml'), array_keys($finder + ->directory('config') + ->suffix('routing.yml') + ->find() + )); + } } /** - * Locate paths containing routing files - * This sets an internal property but does not return the paths. + * Find a list of controllers and return it * - * @return The current instance of this object for method chaining + * @param string $base_path Base path to prepend to file paths + * @return null */ - public function import_paths_from_finder(\phpbb\extension\finder $finder) + public function find($base_path = '') { - // 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() - ))); + $this->routes = new RouteCollection; + foreach ($this->routing_files as $file_path) + { + $loader = new YamlFileLoader(new FileLocator($base_path)); + $this->routes->addCollection($loader->load($file_path)); + } return $this; } /** - * Get a list of controllers and return it + * Get the list of routes * - * @param string $base_path Base path to prepend to file paths - * @return array Array of controllers and their route information + * @return RouteCollection Get the route collection */ - public function find($base_path = '') + public function get_routes() { - $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; + return $this->routes; } } diff --git a/phpBB/phpbb/controller/resolver.php b/phpBB/phpbb/controller/resolver.php index 1cc8981105..233179e343 100644 --- a/phpBB/phpbb/controller/resolver.php +++ b/phpBB/phpbb/controller/resolver.php @@ -9,14 +9,6 @@ namespace phpbb\controller; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; |