From 16dacba4900ce2bbb4f26040f6f5c2b698eae5da Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 12 Aug 2012 16:53:00 +0200 Subject: Routing: And start using them from php --- lib/helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/helper.php') diff --git a/lib/helper.php b/lib/helper.php index 8c362747a27..3cdb3e53c22 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -42,8 +42,8 @@ class OC_Helper { // Check if the app is in the app folder if( $app_path && file_exists( $app_path.'/'.$file )){ if(substr($file, -3) == 'php' || substr($file, -3) == 'css'){ - $urlLinkTo = OC::$WEBROOT . '/?app=' . $app; - $urlLinkTo .= ($file!='index.php')?'&getfile=' . urlencode($file):''; + $urlLinkTo = OC::$WEBROOT . '/index.php/apps/' . $app; + $urlLinkTo .= ($file!='index.php') ? '/' . $file : ''; }else{ $urlLinkTo = OC_App::getAppWebPath($app) . '/' . $file; } -- cgit v1.2.3 From 3efe1d3b24e65ed76d521c24b0cfe4e0ff2e7af5 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 12 Sep 2012 18:00:33 +0200 Subject: Add linkToRoute functionality --- lib/helper.php | 14 ++++++++++++++ lib/router.php | 29 +++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) (limited to 'lib/helper.php') diff --git a/lib/helper.php b/lib/helper.php index ed4bf53250a..269327b531d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -28,6 +28,20 @@ class OC_Helper { private static $mimetypes=array(); private static $tmpFiles=array(); + /** + * @brief Creates an url using a defined route + * @param $route + * @param $parameters + * @param $args array with param=>value, will be appended to the returned url + * @returns the url + * + * Returns a url to the given app and file. + */ + public static function linkToRoute( $route, $parameters = array() ) { + $urlLinkTo = OC::getRouter()->generate($route, $parameters); + return $urlLinkTo; + } + /** * @brief Creates an url * @param $app app diff --git a/lib/router.php b/lib/router.php index 65fc51aff2c..da491e217fc 100644 --- a/lib/router.php +++ b/lib/router.php @@ -7,6 +7,7 @@ */ use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouteCollection; //use Symfony\Component\Routing\Route; @@ -16,7 +17,14 @@ class OC_Router { protected $collection = null; protected $root = null; + protected $generator= null; + public function __construct() { + $baseUrl = OC_Helper::linkTo('', 'index.php'); + $method = $_SERVER['REQUEST_METHOD']; + $host = OC_Request::serverHost(); + $schema = OC_Request::serverProtocol(); + $this->context = new RequestContext($baseUrl, $method, $host, $schema); // TODO cache $this->root = $this->getCollection('root'); } @@ -56,12 +64,7 @@ class OC_Router { } public function match($url) { - $baseUrl = OC_Helper::linkTo('', 'index.php'); - $method = $_SERVER['REQUEST_METHOD']; - $host = OC_Request::serverHost(); - $schema = OC_Request::serverProtocol(); - $context = new RequestContext($baseUrl, $method, $host, $schema); - $matcher = new UrlMatcher($this->root, $context); + $matcher = new UrlMatcher($this->root, $this->context); $parameters = $matcher->match($url); if (isset($parameters['action'])) { $action = $parameters['action']; @@ -77,4 +80,18 @@ class OC_Router { throw new Exception('no action available'); } } + + public function getGenerator() + { + if (null !== $this->generator) { + return $this->generator; + } + + return $this->generator = new UrlGenerator($this->root, $this->context); + } + + public function generate($name, $parameters = array(), $absolute = false) + { + return $this->getGenerator()->generate($name, $parameters, $absolute); + } } -- cgit v1.2.3