From c4012ed71873baeadffd272fe59939341087c99c Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 27 May 2015 23:58:43 +0200 Subject: [PATCH] Create URL generator interface. Also bind a default implementation to the container. --- .../core/src/Core/CoreServiceProvider.php | 5 ++++ framework/core/src/Http/UrlGenerator.php | 28 +++++++++++++++++++ .../core/src/Http/UrlGeneratorInterface.php | 10 +++++++ 3 files changed, 43 insertions(+) create mode 100644 framework/core/src/Http/UrlGenerator.php create mode 100644 framework/core/src/Http/UrlGeneratorInterface.php diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index 55833f4f1..d2cd86e78 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -72,6 +72,11 @@ class CoreServiceProvider extends ServiceProvider $this->app->singleton('flarum.formatter', 'Flarum\Core\Formatter\FormatterManager'); + $this->app->bind( + 'Flarum\Http\UrlGeneratorInterface', + 'Flarum\Http\UrlGenerator' + ); + $this->app->bind( 'Flarum\Core\Repositories\DiscussionRepositoryInterface', 'Flarum\Core\Repositories\EloquentDiscussionRepository' diff --git a/framework/core/src/Http/UrlGenerator.php b/framework/core/src/Http/UrlGenerator.php new file mode 100644 index 000000000..f712102cc --- /dev/null +++ b/framework/core/src/Http/UrlGenerator.php @@ -0,0 +1,28 @@ +router = $router; + } + + public function toRoute($name, $parameters = []) + { + $path = $this->router->getPath($name, $parameters); + $path = ltrim($path, '/'); + + // TODO: Prepend real base URL + return "/$path"; + } + + public function toAsset($path) + { + return "/$path"; + } +} diff --git a/framework/core/src/Http/UrlGeneratorInterface.php b/framework/core/src/Http/UrlGeneratorInterface.php new file mode 100644 index 000000000..98851ea02 --- /dev/null +++ b/framework/core/src/Http/UrlGeneratorInterface.php @@ -0,0 +1,10 @@ +