aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/controller
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-03-07 12:32:38 +0100
committerJoas Schilling <nickvergessen@gmx.de>2014-03-07 12:32:38 +0100
commit51273f6fb1421b68c1931c3960f68cd483f1ee95 (patch)
tree2d982cc9fe52b4a9ee9a3b47a59658ba631c6444 /phpBB/phpbb/controller
parent4b6f3f8b0fc3fc3b0d7fa0147930d0ea02107a8f (diff)
downloadforums-51273f6fb1421b68c1931c3960f68cd483f1ee95.tar
forums-51273f6fb1421b68c1931c3960f68cd483f1ee95.tar.gz
forums-51273f6fb1421b68c1931c3960f68cd483f1ee95.tar.bz2
forums-51273f6fb1421b68c1931c3960f68cd483f1ee95.tar.xz
forums-51273f6fb1421b68c1931c3960f68cd483f1ee95.zip
[ticket/12090] Pass route name to url() to allow admins to change the routes
PHPBB3-12090
Diffstat (limited to 'phpBB/phpbb/controller')
-rw-r--r--phpBB/phpbb/controller/helper.php38
1 files changed, 28 insertions, 10 deletions
diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php
index 05a05d1e57..daa52ec672 100644
--- a/phpBB/phpbb/controller/helper.php
+++ b/phpBB/phpbb/controller/helper.php
@@ -10,6 +10,8 @@
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
@@ -56,13 +58,17 @@ class helper
* @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\extension\finder $finder, \phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, $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;
+
+ $provider = new \phpbb\controller\provider();
+ $this->route_collection = $provider->import_paths_from_finder($finder)->find($this->phpbb_root_path);
+
}
/**
@@ -87,21 +93,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 &amp; (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('&amp;', '&'), array('&', '&amp;'), $route_url);
}
// If enable_mod_rewrite is false, we need to include app.php
@@ -111,7 +129,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);
}
/**