added comments and renamed short method to url generators

This commit is contained in:
msquare 2018-08-06 12:50:34 +02:00
parent 5a83d4fb8b
commit 86b2937078
8 changed files with 28 additions and 12 deletions

View File

@ -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;

View File

@ -1,11 +1,14 @@
<?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');

View File

@ -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');

View File

@ -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 = []);
}

View File

@ -124,7 +124,7 @@ function url($path = null, $parameters = [])
return $urlGenerator;
}
return $urlGenerator->to($path, $parameters);
return $urlGenerator->link_to($path, $parameters);
}
/**

View File

@ -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');

View File

@ -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);
}
}

View File

@ -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);
}
}