summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2018-08-06 12:50:34 +0200
committermsquare <msquare@notrademark.de>2018-08-06 12:50:34 +0200
commit86b29370786de35cc40e3424e09c3cf48551ee28 (patch)
tree7d605f5b24c864d91c50bfe9df333f95d272f7b5
parent5a83d4fb8b7d2fc561a2b841ab6981df02837b2d (diff)
added comments and renamed short method to url generators
-rw-r--r--src/Routing/LegacyUrlGenerator.php11
-rw-r--r--src/Routing/RoutingServiceProvider.php7
-rw-r--r--src/Routing/UrlGenerator.php9
-rw-r--r--src/Routing/UrlGeneratorInterface.php5
-rw-r--r--src/helpers.php2
-rw-r--r--tests/Unit/HelpersTest.php2
-rw-r--r--tests/Unit/Routing/LegacyUrlGeneratorTest.php2
-rw-r--r--tests/Unit/Routing/UrlGeneratorTest.php2
8 files changed, 28 insertions, 12 deletions
diff --git a/src/Routing/LegacyUrlGenerator.php b/src/Routing/LegacyUrlGenerator.php
index f17bdf88..e2434e1f 100644
--- a/src/Routing/LegacyUrlGenerator.php
+++ b/src/Routing/LegacyUrlGenerator.php
@@ -2,14 +2,19 @@
namespace Engelsystem\Routing;
+/**
+ * Provides urls when webserver rewriting is disabled.
+ *
+ * The urls have the form <app url>/index.php?p=<path>&<parameters>
+ */
class LegacyUrlGenerator extends UrlGenerator
{
/**
* @param string $path
* @param array $parameters
- * @return string
+ * @return string urls in the form <app url>/index.php?p=<path>&<parameters>
*/
- public function to($path, $parameters = [])
+ public function link_to($path, $parameters = [])
{
$page = ltrim($path, '/');
if (!empty($page)) {
@@ -17,7 +22,7 @@ class LegacyUrlGenerator extends UrlGenerator
$parameters = array_merge(['p' => $page], $parameters);
}
- $uri = parent::to('index.php', $parameters);
+ $uri = parent::link_to('index.php', $parameters);
$uri = preg_replace('~(/index\.php)+~', '/index.php', $uri);
return $uri;
diff --git a/src/Routing/RoutingServiceProvider.php b/src/Routing/RoutingServiceProvider.php
index 021840c3..beaa6a94 100644
--- a/src/Routing/RoutingServiceProvider.php
+++ b/src/Routing/RoutingServiceProvider.php
@@ -1,16 +1,19 @@
<?php
-
namespace Engelsystem\Routing;
use Engelsystem\Container\ServiceProvider;
+/**
+ * Registers the url generator depending on config.
+ */
class RoutingServiceProvider extends ServiceProvider
{
+
public function register()
{
$config = $this->app->get('config');
$class = UrlGenerator::class;
- if (!$config->get('rewrite_urls', true)) {
+ if (! $config->get('rewrite_urls', true)) {
$class = LegacyUrlGenerator::class;
}
diff --git a/src/Routing/UrlGenerator.php b/src/Routing/UrlGenerator.php
index 8dd52271..a8fc88c1 100644
--- a/src/Routing/UrlGenerator.php
+++ b/src/Routing/UrlGenerator.php
@@ -2,14 +2,19 @@
namespace Engelsystem\Routing;
+/**
+ * Provides urls when rewriting on the webserver is enabled. (default)
+ *
+ * The urls have the form <app url>/<path>?<parameters>
+ */
class UrlGenerator implements UrlGeneratorInterface
{
/**
* @param string $path
* @param array $parameters
- * @return string
+ * @return string url in the form [app url]/[path]?[parameters]
*/
- public function to($path, $parameters = [])
+ public function link_to($path, $parameters = [])
{
$path = '/' . ltrim($path, '/');
$request = app('request');
diff --git a/src/Routing/UrlGeneratorInterface.php b/src/Routing/UrlGeneratorInterface.php
index d97da30d..17385bc2 100644
--- a/src/Routing/UrlGeneratorInterface.php
+++ b/src/Routing/UrlGeneratorInterface.php
@@ -2,6 +2,9 @@
namespace Engelsystem\Routing;
+/**
+ * To switch between different URL schemes.
+ */
interface UrlGeneratorInterface
{
/**
@@ -9,5 +12,5 @@ interface UrlGeneratorInterface
* @param array $parameters
* @return string
*/
- public function to($path, $parameters = []);
+ public function link_to($path, $parameters = []);
}
diff --git a/src/helpers.php b/src/helpers.php
index 1915eb86..8b1f0cee 100644
--- a/src/helpers.php
+++ b/src/helpers.php
@@ -124,7 +124,7 @@ function url($path = null, $parameters = [])
return $urlGenerator;
}
- return $urlGenerator->to($path, $parameters);
+ return $urlGenerator->link_to($path, $parameters);
}
/**
diff --git a/tests/Unit/HelpersTest.php b/tests/Unit/HelpersTest.php
index fcb7231d..01ff99b1 100644
--- a/tests/Unit/HelpersTest.php
+++ b/tests/Unit/HelpersTest.php
@@ -177,7 +177,7 @@ class HelpersTest extends TestCase
$this->assertEquals($urlGeneratorMock, url());
$urlGeneratorMock->expects($this->once())
- ->method('to')
+ ->method('link_to')
->with('foo/bar', ['param' => 'value'])
->willReturn('http://lorem.ipsum/foo/bar?param=value');
diff --git a/tests/Unit/Routing/LegacyUrlGeneratorTest.php b/tests/Unit/Routing/LegacyUrlGeneratorTest.php
index 63e1a3eb..7c28eaed 100644
--- a/tests/Unit/Routing/LegacyUrlGeneratorTest.php
+++ b/tests/Unit/Routing/LegacyUrlGeneratorTest.php
@@ -48,7 +48,7 @@ class LegacyUrlGeneratorTest extends TestCase
$urlGenerator = new LegacyUrlGenerator();
$this->assertInstanceOf(UrlGeneratorInterface::class, $urlGenerator);
- $url = $urlGenerator->to($urlToPath, $arguments);
+ $url = $urlGenerator->link_to($urlToPath, $arguments);
$this->assertEquals($expectedUrl, $url);
}
}
diff --git a/tests/Unit/Routing/UrlGeneratorTest.php b/tests/Unit/Routing/UrlGeneratorTest.php
index 8fe0d65f..34c2f610 100644
--- a/tests/Unit/Routing/UrlGeneratorTest.php
+++ b/tests/Unit/Routing/UrlGeneratorTest.php
@@ -48,7 +48,7 @@ class UrlGeneratorTest extends TestCase
$urlGenerator = new UrlGenerator();
$this->assertInstanceOf(UrlGeneratorInterface::class, $urlGenerator);
- $url = $urlGenerator->to($urlToPath, $arguments);
+ $url = $urlGenerator->link_to($urlToPath, $arguments);
$this->assertEquals($expectedUrl, $url);
}
}