404
++
Page not found.
+The page you requested could not be found.
+diff --git a/composer.json b/composer.json index 679fdbe9..caf5e5dd 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,6 @@ "mezzio/mezzio": "^3.2", "mezzio/mezzio-fastroute": "^3.0", "mezzio/mezzio-helpers": "^5.3", - "mezzio/mezzio-platesrenderer": "^2.1", "mezzio/mezzio-problem-details": "^1.1", "mezzio/mezzio-swoole": "^2.6.4", "monolog/monolog": "^2.0", diff --git a/config/autoload/templates.global.php b/config/autoload/templates.global.php deleted file mode 100644 index e1b457fa..00000000 --- a/config/autoload/templates.global.php +++ /dev/null @@ -1,17 +0,0 @@ - [ - 'extension' => 'phtml', - ], - - 'plates' => [ - 'extensions' => [ - // extension service names or instances - ], - ], - -]; diff --git a/config/config.php b/config/config.php index ba0657fc..cf9eb86b 100644 --- a/config/config.php +++ b/config/config.php @@ -15,7 +15,6 @@ return (new ConfigAggregator\ConfigAggregator([ Mezzio\ConfigProvider::class, Mezzio\Router\ConfigProvider::class, Mezzio\Router\FastRouteRouter\ConfigProvider::class, - Mezzio\Plates\ConfigProvider::class, Mezzio\Swoole\ConfigProvider::class, ProblemDetails\ConfigProvider::class, Diactoros\ConfigProvider::class, diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index b6beb1ac..94b5858a 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core; use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory; -use Mezzio\Template\TemplateRendererInterface; +use Laminas\ServiceManager\Factory\InvokableFactory; use Psr\EventDispatcher\EventDispatcherInterface; use Shlinkio\Shlink\Core\ErrorHandler; use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; @@ -16,7 +16,7 @@ return [ 'dependencies' => [ 'factories' => [ ErrorHandler\NotFoundRedirectHandler::class => ConfigAbstractFactory::class, - ErrorHandler\NotFoundTemplateHandler::class => ConfigAbstractFactory::class, + ErrorHandler\NotFoundTemplateHandler::class => InvokableFactory::class, Options\AppOptions::class => ConfigAbstractFactory::class, Options\DeleteShortUrlsOptions::class => ConfigAbstractFactory::class, @@ -60,7 +60,6 @@ return [ Util\RedirectResponseHelper::class, 'config.router.base_path', ], - ErrorHandler\NotFoundTemplateHandler::class => [TemplateRendererInterface::class], Options\AppOptions::class => ['config.app_options'], Options\DeleteShortUrlsOptions::class => ['config.delete_short_urls'], diff --git a/module/Core/config/mezzio.config.php b/module/Core/config/mezzio.config.php deleted file mode 100644 index 5e4acb22..00000000 --- a/module/Core/config/mezzio.config.php +++ /dev/null @@ -1,14 +0,0 @@ - [ - 'error_handler' => [ - 'template_404' => 'ShlinkCore::error/404', - 'template_error' => 'ShlinkCore::error/error', - ], - ], - -]; diff --git a/module/Core/config/templates.config.php b/module/Core/config/templates.config.php deleted file mode 100644 index 784f731e..00000000 --- a/module/Core/config/templates.config.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - 'paths' => [ - 'ShlinkCore' => __DIR__ . '/../templates', - ], - ], - -]; diff --git a/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php b/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php index e5968a68..62b78973 100644 --- a/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php +++ b/module/Core/src/ErrorHandler/NotFoundTemplateHandler.php @@ -4,40 +4,37 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ErrorHandler; +use Closure; use Fig\Http\Message\StatusCodeInterface; -use InvalidArgumentException; use Laminas\Diactoros\Response; use Mezzio\Router\RouteResult; -use Mezzio\Template\TemplateRendererInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; +use function file_get_contents; +use function sprintf; + class NotFoundTemplateHandler implements RequestHandlerInterface { - public const NOT_FOUND_TEMPLATE = 'ShlinkCore::error/404'; - public const INVALID_SHORT_CODE_TEMPLATE = 'ShlinkCore::invalid-short-code'; + private const TEMPLATES_BASE_DIR = __DIR__ . '/../../templates'; + public const NOT_FOUND_TEMPLATE = '404.html'; + public const INVALID_SHORT_CODE_TEMPLATE = 'invalid-short-code.html'; + private Closure $readFile; - private TemplateRendererInterface $renderer; - - public function __construct(TemplateRendererInterface $renderer) + public function __construct(?callable $readFile = null) { - $this->renderer = $renderer; + $this->readFile = $readFile ? Closure::fromCallable($readFile) : fn (string $file) => file_get_contents($file); } - /** - * Dispatch the next available middleware and return the response. - * - * - * @throws InvalidArgumentException - */ public function handle(ServerRequestInterface $request): ResponseInterface { /** @var RouteResult $routeResult */ - $routeResult = $request->getAttribute(RouteResult::class, RouteResult::fromRouteFailure(null)); + $routeResult = $request->getAttribute(RouteResult::class) ?? RouteResult::fromRouteFailure(null); $status = StatusCodeInterface::STATUS_NOT_FOUND; $template = $routeResult->isFailure() ? self::NOT_FOUND_TEMPLATE : self::INVALID_SHORT_CODE_TEMPLATE; - return new Response\HtmlResponse($this->renderer->render($template), $status); + $templateContent = ($this->readFile)(sprintf('%s/%s', self::TEMPLATES_BASE_DIR, $template)); + return new Response\HtmlResponse($templateContent, $status); } } diff --git a/module/Core/templates/404.html b/module/Core/templates/404.html new file mode 100644 index 00000000..93e6fb64 --- /dev/null +++ b/module/Core/templates/404.html @@ -0,0 +1,27 @@ + + +
+The page you requested could not be found.
+The page you requested could not be found.
-end() ?> diff --git a/module/Core/templates/error/error.phtml b/module/Core/templates/error/error.phtml deleted file mode 100644 index 77108f26..00000000 --- a/module/Core/templates/error/error.phtml +++ /dev/null @@ -1,25 +0,0 @@ -layout('ShlinkCore::layout/default') ?> - -start('title') ?> - = $this->e($status . ' ' . $reason) ?> -end() ?> - -start('stylesheets') ?> - -end() ?> - -start('main') ?> -= sprintf('We encountered a %s %s error.', $status, $reason) ?>
- -'This short URL doesn't seem to be valid.
-'Make sure you included all the characters, with no extra punctuation.
- -end() ?> - diff --git a/module/Core/templates/invalid-short-code.html b/module/Core/templates/invalid-short-code.html new file mode 100644 index 00000000..61c5a804 --- /dev/null +++ b/module/Core/templates/invalid-short-code.html @@ -0,0 +1,27 @@ + + + +This short URL doesn't seem to be valid.
+Make sure you included all the characters, with no extra punctuation.
+This short URL doesn't seem to be valid.
-Make sure you included all the characters, with no extra punctuation.
-end() ?> diff --git a/module/Core/templates/layout/default.phtml b/module/Core/templates/layout/default.phtml deleted file mode 100644 index fbb78b26..00000000 --- a/module/Core/templates/layout/default.phtml +++ /dev/null @@ -1,23 +0,0 @@ - - - -