Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
"require": {
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
"dotkernel/dot-controller": "^4.0.1",
"dotkernel/dot-errorhandler": "^4.1.1",
"laminas/laminas-component-installer": "^3.5.0",
"laminas/laminas-config-aggregator": "^1.17.0",
Expand Down
6 changes: 6 additions & 0 deletions config/autoload/local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ return [
'application' => [
'url' => $baseUrl,
],
'routes' => [
'page' => [
'about' => 'about',
'who-we-are' => 'who-we-are',
],
],
];
15 changes: 14 additions & 1 deletion src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace Light\App;

use Light\App\Factory\IndexHandlerFactory;
use Light\App\Handler\IndexHandler;
use Mezzio\Application;

class ConfigProvider
{
public function __invoke(): array
Expand All @@ -16,7 +20,16 @@ public function __invoke(): array

public function getDependencies(): array
{
return [];
return [
'delegators' => [
Application::class => [
RoutesDelegator::class,
],
],
'factories' => [
IndexHandler::class => IndexHandlerFactory::class,
],
];
}

public function getTemplates(): array
Expand Down
29 changes: 29 additions & 0 deletions src/App/src/Factory/IndexHandlerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Light\App\Factory;

use Light\App\Handler\IndexHandler;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

use function assert;

class IndexHandlerFactory
{
/**
* @param class-string $requestedName
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container, string $requestedName): IndexHandler

Check warning on line 22 in src/App/src/Factory/IndexHandlerFactory.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'string'
{
$template = $container->get(TemplateRendererInterface::class);
assert($template instanceof TemplateRendererInterface);

return new IndexHandler($template);
}
}
26 changes: 26 additions & 0 deletions src/App/src/Handler/IndexHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Light\App\Handler;

use Laminas\Diactoros\Response\HtmlResponse;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class IndexHandler implements RequestHandlerInterface
{
public function __construct(
protected TemplateRendererInterface $template
) {
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
return new HtmlResponse(
$this->template->render('app::index')

Check warning on line 23 in src/App/src/Handler/IndexHandler.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Parameter type

Parameter ''app::index'' type is not compatible with declaration
);
}
}
24 changes: 24 additions & 0 deletions src/App/src/RoutesDelegator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Light\App;

use Light\App\Handler\IndexHandler;
use Mezzio\Application;
use Psr\Container\ContainerInterface;

use function assert;

class RoutesDelegator
{
public function __invoke(ContainerInterface $container, string $serviceName, callable $callback): Application

Check warning on line 15 in src/App/src/RoutesDelegator.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'string'
{
$app = $callback();
assert($app instanceof Application);

$app->get('/', [IndexHandler::class], 'app::index');

return $app;
}
}
17 changes: 0 additions & 17 deletions src/App/templates/error/403.html.twig

This file was deleted.

4 changes: 2 additions & 2 deletions src/App/templates/error/404.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<h2>Oops!</h2>
<h2>This is awkward.</h2>
<h1>404</h1>
<p>
<p class="text-dark">
You are looking for something that doesn't exist or may have moved. Check out one of the links on this page
or head back to <a href="{{ path('home') }}">Home</a>.
or head back to <a class="text-dark" href="{{ path('app::index') }}">Home</a>.
</p>
</div>
</div>
Expand Down
7 changes: 1 addition & 6 deletions src/App/templates/error/error.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends '@layout/default.html.twig' %}

{% block title %}{{ status }} {{ reason }}{% endblock %}
{% block canonical %}{% endblock %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arhimede
It's not a 404 page, so we have a matched route, which means that we CAN parse the canonical URL of the page.
Not sure if we SHOULD, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not bother to have a canonical in 404 pages

It doesn't matter in the slightest for Google, all content, including headers, are dropped when a 404 status code is seen.
So no matter what you'd put in there, google wouldn't process and use it.

Copy link
Member

@alexmerlin alexmerlin Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said:

It's not a 404 page, so we have a matched route...

My question was if we should have a canonical URL on a 500 (or any other non-404) page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, useless


{% block content %}
<div class="page-intro home-intro error-messages">
Expand All @@ -9,12 +10,6 @@
<h2>This is awkward.</h2>
<h1>{{ status }}</h1>
<h2 class="message">{{ reason }}</h2>
{% if status == 404 %}
<p>
You are looking for something that doesn't exist or may have moved. Check out one of the links on this page
or head back to <a href="{{ path('home') }}">Home</a>.
</p>
{% endif %}
</div>
</div>
{% endblock %}
11 changes: 4 additions & 7 deletions src/App/templates/layout/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />

<title>{% block title %}{% endblock %} | Dotkernel Light V1</title>
{% block canonical %}
<link rel="canonical" href="{{ url(routeName ?? null) }}" />
{% endblock %}
{% block canonical %}<link rel="canonical" href="{{ url(routeName ?? null) }}" />{% endblock %}

<link rel="apple-touch-icon" sizes="180x180" href="{{ asset('images/app/favicon/apple-touch-icon.png') }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ asset('images/app/favicon/favicon-32x32.png') }}">
Expand Down Expand Up @@ -46,16 +44,15 @@
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="pageDropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Pages</a>
<div class="dropdown-menu" aria-labelledby="pageDropdown">
<a class="dropdown-item" href="{{ url('page', {action: 'home'}) }}">Home</a>
<a class="dropdown-item" href="{{ url('page', {action: 'about-us'}) }}">About Us</a>
<a class="dropdown-item" href="{{ url('page', {action: 'who-we-are'}) }}">Who We Are</a>
<a class="dropdown-item" href="{{ url('page::about') }}">About Us</a>
<a class="dropdown-item" href="{{ url('page::who-we-are') }}">Who We Are</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/dotkernel/light/" target="_blank">GitHub</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="{{ url('page', {action: 'index'}) }}">Disabled</a>
<a class="nav-link disabled" href="{{ url('app::index') }}">Disabled</a>
</li>
</ul>
</div>
Expand Down
9 changes: 5 additions & 4 deletions src/Page/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace Light\Page;

use Light\Page\Controller\PageController;
use Light\Page\Factory\PageControllerFactory;
use Light\Page\Factory\PageHandlerFactory;
use Light\Page\Factory\PageServiceFactory;
use Light\Page\Handler\PageHandler;
use Light\Page\RoutesDelegator;
use Light\Page\Service\PageService;
use Light\Page\Service\PageServiceInterface;
use Mezzio\Application;
Expand All @@ -30,8 +31,8 @@ public function getDependencies(): array
],
],
'factories' => [
PageController::class => PageControllerFactory::class,
PageService::class => PageServiceFactory::class,
PageHandler::class => PageHandlerFactory::class,
PageService::class => PageServiceFactory::class,
],
'aliases' => [
PageServiceInterface::class => PageService::class,
Expand Down
50 changes: 0 additions & 50 deletions src/Page/src/Controller/PageController.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,26 @@

namespace Light\Page\Factory;

use Light\Page\Controller\PageController;
use Light\Page\Service\PageServiceInterface;
use Mezzio\Router\RouterInterface;
use Light\Page\Handler\PageHandler;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

use function assert;

class PageControllerFactory
class PageHandlerFactory
{
/**
* @param class-string $requestedName
* @throws NotFoundExceptionInterface
* @throws ContainerExceptionInterface
*/
public function __invoke(ContainerInterface $container, string $requestedName): PageController
public function __invoke(ContainerInterface $container, string $requestedName): PageHandler

Check warning on line 22 in src/Page/src/Factory/PageHandlerFactory.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'string'
{
$pageService = $container->get(PageServiceInterface::class);
assert($pageService instanceof PageServiceInterface);

$router = $container->get(RouterInterface::class);
assert($router instanceof RouterInterface);

$template = $container->get(TemplateRendererInterface::class);
assert($template instanceof TemplateRendererInterface);

return new PageController($pageService, $router, $template);
return new PageHandler($template);
}
}
3 changes: 3 additions & 0 deletions src/Page/src/Factory/PageServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class PageServiceFactory
{
/**
* @param class-string $requestedName
*/
public function __invoke(ContainerInterface $container, string $requestedName): PageServiceInterface
{
return new PageService();
Expand Down
29 changes: 29 additions & 0 deletions src/Page/src/Handler/PageHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Light\Page\Handler;

use Laminas\Diactoros\Response\HtmlResponse;
use Mezzio\Router\RouteResult;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class PageHandler implements RequestHandlerInterface
{
public function __construct(
protected TemplateRendererInterface $template,
) {
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$template = $request->getAttribute(RouteResult::class)->getMatchedRouteName();

return new HtmlResponse(
$this->template->render($template)
);
}
}
Loading
Loading