aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/controller
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/controller')
-rw-r--r--phpBB/phpbb/controller/exception.php10
-rw-r--r--phpBB/phpbb/controller/helper.php77
-rw-r--r--phpBB/phpbb/controller/provider.php73
-rw-r--r--phpBB/phpbb/controller/resolver.php44
4 files changed, 101 insertions, 103 deletions
diff --git a/phpBB/phpbb/controller/exception.php b/phpBB/phpbb/controller/exception.php
index faa8b6b584..06ece8d1d5 100644
--- a/phpBB/phpbb/controller/exception.php
+++ b/phpBB/phpbb/controller/exception.php
@@ -7,18 +7,12 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\controller;
/**
* Controller exception class
* @package phpBB3
*/
-class phpbb_controller_exception extends RuntimeException
+class exception extends \RuntimeException
{
}
diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php
index 4d240f9380..54c30c93fc 100644
--- a/phpBB/phpbb/controller/helper.php
+++ b/phpBB/phpbb/controller/helper.php
@@ -7,39 +7,35 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\controller;
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
* @package phpBB3
*/
-class phpbb_controller_helper
+class helper
{
/**
* Template object
- * @var phpbb_template
+ * @var \phpbb\template\template
*/
protected $template;
/**
* User object
- * @var phpbb_user
+ * @var \phpbb\user
*/
protected $user;
/**
- * Request object
- * @var phpbb_request
+ * config object
+ * @var \phpbb\config\config
*/
- protected $request;
+ protected $config;
/**
* phpBB root path
@@ -56,18 +52,21 @@ class phpbb_controller_helper
/**
* Constructor
*
- * @param phpbb_template $template Template object
- * @param phpbb_user $user User object
+ * @param \phpbb\template\template $template Template 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, phpbb_user $user, phpbb_request_interface $request, $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->request = $request;
+ $this->config = $config;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
+ $this->route_collection = $provider->get_routes();
}
/**
@@ -78,9 +77,9 @@ class phpbb_controller_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,
@@ -92,33 +91,43 @@ class phpbb_controller_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['#']))
{
- $route_params = substr($route, $route_delim);
- $route = substr($route, 0, $route_delim);
+ $anchor = '#' . $params['#'];
+ unset($params['#']);
}
+ $url_generator = new UrlGenerator($this->route_collection, new RequestContext());
+ $route_url = $url_generator->generate($route, $params);
- $request_uri = $this->request->variable('REQUEST_URI', '', false, phpbb_request::SERVER);
- $script_name = $this->request->variable('SCRIPT_NAME', '', false, phpbb_request::SERVER);
+ if (strpos($route_url, '/') === 0)
+ {
+ $route_url = substr($route_url, 1);
+ }
- // If the app.php file is being used (no rewrite) keep it in the URL.
- // Otherwise, don't include it.
+ if ($is_amp)
+ {
+ $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url);
+ }
+
+ // If enable_mod_rewrite is false, we need to include app.php
$route_prefix = $this->phpbb_root_path;
- $parts = explode('/', $script_name);
- $route_prefix .= strpos($request_uri, $script_name) === 0 ? array_pop($parts) . '/' : '';
+ if (empty($this->config['enable_mod_rewrite']))
+ {
+ $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 b2a5b9f6b2..9df8130210 100644
--- a/phpBB/phpbb/controller/provider.php
+++ b/phpBB/phpbb/controller/provider.php
@@ -7,13 +7,7 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\controller;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Loader\YamlFileLoader;
@@ -23,60 +17,67 @@ use Symfony\Component\Config\FileLocator;
* Controller interface
* @package phpBB3
*/
-class phpbb_controller_provider
+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 d772507261..233179e343 100644
--- a/phpBB/phpbb/controller/resolver.php
+++ b/phpBB/phpbb/controller/resolver.php
@@ -7,13 +7,7 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\controller;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -23,11 +17,11 @@ use Symfony\Component\HttpFoundation\Request;
* Controller manager class
* @package phpBB3
*/
-class phpbb_controller_resolver implements ControllerResolverInterface
+class resolver implements ControllerResolverInterface
{
/**
* User object
- * @var phpbb_user
+ * @var \phpbb\user
*/
protected $user;
@@ -38,19 +32,19 @@ class phpbb_controller_resolver implements ControllerResolverInterface
protected $container;
/**
- * phpbb_template object
- * @var phpbb_template
+ * phpbb\template\template object
+ * @var phpbb\template\template
*/
protected $template;
/**
* Construct method
*
- * @param phpbb_user $user User Object
+ * @param \phpbb\user $user User Object
* @param ContainerInterface $container ContainerInterface object
- * @param phpbb_template $template
+ * @param \phpbb\template\template $template
*/
- public function __construct(phpbb_user $user, ContainerInterface $container, phpbb_template $template = null)
+ public function __construct(\phpbb\user $user, ContainerInterface $container, \phpbb\template\template $template = null)
{
$this->user = $user;
$this->container = $container;
@@ -62,7 +56,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface
*
* @param Symfony\Component\HttpFoundation\Request $request Symfony Request object
* @return bool|Callable Callable or false
- * @throws phpbb_controller_exception
+ * @throws \phpbb\controller\exception
*/
public function getController(Request $request)
{
@@ -70,20 +64,20 @@ class phpbb_controller_resolver implements ControllerResolverInterface
if (!$controller)
{
- throw new phpbb_controller_exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']);
+ 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']);
+ 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));
+ throw new \phpbb\controller\exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service));
}
$controller_object = $this->container->get($service);
@@ -93,12 +87,12 @@ class phpbb_controller_resolver implements ControllerResolverInterface
* the style paths for the extension (the ext author can change them
* if necessary).
*/
- $controller_dir = explode('_', get_class($controller_object));
+ $controller_dir = explode('\\', get_class($controller_object));
- // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ...
- if (!is_null($this->template) && isset($controller_dir[3]) && $controller_dir[1] === 'ext')
+ // 0 vendor, 1 extension name, ...
+ if (!is_null($this->template) && isset($controller_dir[1]))
{
- $controller_style_dir = 'ext/' . $controller_dir[2] . '/' . $controller_dir[3] . '/styles';
+ $controller_style_dir = 'ext/' . $controller_dir[0] . '/' . $controller_dir[1] . '/styles';
if (is_dir($controller_style_dir))
{
@@ -118,13 +112,13 @@ class phpbb_controller_resolver implements ControllerResolverInterface
* @param Symfony\Component\HttpFoundation\Request $request Symfony Request object
* @param mixed $controller A callable (controller class, method)
* @return bool False
- * @throws phpbb_controller_exception
+ * @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);
+ $mirror = new \ReflectionMethod($object, $method);
$arguments = array();
$parameters = $mirror->getParameters();
@@ -145,7 +139,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface
}
else
{
- throw new phpbb_controller_exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name));
+ throw new \phpbb\controller\exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name));
}
}