Removed LegacyUrlGenerator

This commit is contained in:
Igor Scheller 2020-04-06 19:35:59 +02:00 committed by msquare
parent d323b75501
commit 6b1c22a743
4 changed files with 3 additions and 88 deletions

View File

@ -80,9 +80,6 @@ return [
'1' => 'Engelsystem dark', '1' => 'Engelsystem dark',
], ],
// Rewrite URLs with mod_rewrite
'rewrite_urls' => true,
// Redirect to this site after logging in or when pressing the top-left button // Redirect to this site after logging in or when pressing the top-left button
// Must be one of news, meetings, user_shifts, angeltypes, user_questions // Must be one of news, meetings, user_shifts, angeltypes, user_questions
'home_site' => 'news', 'home_site' => 'news',

View File

@ -1,31 +0,0 @@
<?php
namespace Engelsystem\Http;
/**
* 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 urls in the form <app url>/index.php?p=<path>&<parameters>
*/
public function to($path, $parameters = [])
{
$page = ltrim($path, '/');
if (!empty($page)) {
$page = str_replace('-', '_', $page);
$parameters = array_merge(['p' => $page], $parameters);
}
$uri = parent::to('index.php', $parameters);
$uri = preg_replace('~(/index\.php)+~', '/index.php', $uri);
$uri = preg_replace('~(/index\.php)$~', '/', $uri);
return $uri;
}
}

View File

@ -110,6 +110,7 @@ function redirect(string $path, $status = 302, $headers = []): Response
*/ */
function request($key = null, $default = null) function request($key = null, $default = null)
{ {
/** @var Request $request */
$request = app('request'); $request = app('request');
if (is_null($key)) { if (is_null($key)) {
@ -215,6 +216,7 @@ function _e($key, $keyPlural, $number, $replace = []): string
*/ */
function url($path = null, $parameters = []) function url($path = null, $parameters = [])
{ {
/** @var UrlGeneratorInterface $urlGenerator */
$urlGenerator = app('http.urlGenerator'); $urlGenerator = app('http.urlGenerator');
if (is_null($path)) { if (is_null($path)) {
@ -231,6 +233,7 @@ function url($path = null, $parameters = [])
*/ */
function view($template = null, $data = []) function view($template = null, $data = [])
{ {
/** @var Renderer $renderer */
$renderer = app('renderer'); $renderer = app('renderer');
if (is_null($template)) { if (is_null($template)) {

View File

@ -1,54 +0,0 @@
<?php
namespace Engelsystem\Test\Unit\Http;
use Engelsystem\Application;
use Engelsystem\Container\Container;
use Engelsystem\Http\LegacyUrlGenerator;
use Engelsystem\Http\Request;
use Engelsystem\Http\UrlGeneratorInterface;
use PHPUnit\Framework\TestCase;
class LegacyUrlGeneratorTest extends TestCase
{
public function provideLinksTo()
{
return [
['/', 'http://foo.bar/index.php', [], 'http://foo.bar/'],
['/foo-path', 'http://foo.bar/index.php/index.php', [], 'http://foo.bar/index.php?p=foo_path'],
['/foo', 'http://foo.bar/index.php/index.php', [], 'http://foo.bar/index.php?p=foo'],
['foo', 'http://foo.bar/index.php', ['test' => 'abc'], 'http://foo.bar/index.php?p=foo&test=abc'],
];
}
/**
* @dataProvider provideLinksTo
* @covers \Engelsystem\Http\LegacyUrlGenerator::to
*
* @param string $urlToPath
* @param string $willReturn
* @param string[] $arguments
* @param string $expectedUrl
*/
public function testTo($urlToPath, $willReturn, $arguments, $expectedUrl)
{
$app = new Container();
Application::setInstance($app);
$request = $this->getMockBuilder(Request::class)
->getMock();
$request->expects($this->once())
->method('getUriForPath')
->with('/index.php')
->willReturn($willReturn);
$app->instance('request', $request);
$urlGenerator = new LegacyUrlGenerator();
$this->assertInstanceOf(UrlGeneratorInterface::class, $urlGenerator);
$url = $urlGenerator->to($urlToPath, $arguments);
$this->assertEquals($expectedUrl, $url);
}
}