mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-26 07:15:30 +02:00
Removed unused BaseHref view function
This commit is contained in:
@@ -15,7 +15,6 @@ class TwigProvider
|
||||
/** @const Constant description */
|
||||
protected const VIEW_FUNCTIONS = [
|
||||
ViewFunctions\Asset::class,
|
||||
ViewFunctions\BaseHref::class,
|
||||
ViewFunctions\Breadcrumbs::class,
|
||||
ViewFunctions\Config::class,
|
||||
ViewFunctions\Icon::class,
|
||||
|
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\ViewFunctions;
|
||||
|
||||
class BaseHref extends ViewFunction
|
||||
{
|
||||
/** @var string The function name */
|
||||
protected $name = 'base_href';
|
||||
|
||||
/**
|
||||
* Return the URL for a given path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __invoke(): string
|
||||
{
|
||||
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
|
||||
$baseHref = sprintf('%s://%s%s', $protocol, $_SERVER['HTTP_HOST'] ?? 'localhost', dirname($_SERVER['SCRIPT_NAME']));
|
||||
|
||||
return rtrim($baseHref, '/') . '/';
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\ViewFunctions;
|
||||
|
||||
use App\ViewFunctions\BaseHref;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BaseHrefTest extends TestCase
|
||||
{
|
||||
public function teardown(): void
|
||||
{
|
||||
unset($_SERVER['HTTPS'], $_SERVER['SCRIPT_NAME']);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_it_can_return_the_base_href(): void
|
||||
{
|
||||
$baseHref = new BaseHref($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('http://localhost/', $baseHref());
|
||||
}
|
||||
|
||||
public function test_it_return_the_base_href_when_using_https(): void
|
||||
{
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
|
||||
$baseHref = new BaseHref($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('https://localhost/', $baseHref());
|
||||
}
|
||||
|
||||
public function test_it_can_return_the_base_href_when_in_a_subdirectory(): void
|
||||
{
|
||||
$_SERVER['SCRIPT_NAME'] = '/some/dir/index.php';
|
||||
|
||||
$baseHref = new BaseHref($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('http://localhost/some/dir/', $baseHref());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user