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
30 changes: 14 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,23 @@
},
"require": {
"php": "~8.4.0",
"dotkernel/dot-controller": "^4.0.0",
"dotkernel/dot-errorhandler": "^4.1.0",
"friendsofphp/proxy-manager-lts": "^1.0.16",
"laminas/laminas-component-installer": "^3.4.0",
"laminas/laminas-config-aggregator": "^1.14.0",
"mezzio/mezzio": "^3.18.0",
"mezzio/mezzio-fastroute": "^3.11.0",
"mezzio/mezzio-twigrenderer": "^2.12"
"dotkernel/dot-errorhandler": "^4.1.1",
"laminas/laminas-component-installer": "^3.5.0",
"laminas/laminas-config-aggregator": "^1.17.0",
"mezzio/mezzio": "^3.20.1",
"mezzio/mezzio-fastroute": "^3.12.0",
"mezzio/mezzio-twigrenderer": "^2.17"
},
"require-dev": {
"filp/whoops": "^2.16.0",
"laminas/laminas-coding-standard": "^3.0",
"laminas/laminas-development-mode": "^3.12.0",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5",
"filp/whoops": "^2.17.0",
"laminas/laminas-coding-standard": "^3.0.1",
"laminas/laminas-development-mode": "^3.13.0",
"phpstan/phpstan": "^2.1.2",
"phpstan/phpstan-phpunit": "^2.0.4",
"phpunit/phpunit": "^10.5.45",
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^7.1",
"vincentlanglet/twig-cs-fixer": "^3.5"
"symfony/var-dumper": "^7.2.3",
"vincentlanglet/twig-cs-fixer": "^3.5.1"
},
"autoload": {
"psr-4": {
Expand Down
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
{
$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')
);
}
}
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
{
$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 %}

{% 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 %}
10 changes: 4 additions & 6 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>PHP skeleton to build REST API | {% block title %}{% endblock %}</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 All @@ -24,14 +22,14 @@
<meta name="twitter:description"
content="An opinionated framework-less tool aimed at intermediate-to-advanced level programmers to start
implementing REST APIs swiftly and efficiently.">
<meta name="twitter:image" content="{{ url('home') }}images/app/twitter-card-api.png">
<meta name="twitter:image" content="{{ url('app::index') }}images/app/twitter-card-api.png">
<meta name="twitter:image:alt" content="PHP REST API application | Dotkernel Application">

<!-- OpenGraph card -->
<meta property="og:title" content="PHP REST API application | Dotkernel Application"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="{{ url('home') }}"/>
<meta property="og:image" content="{{ url('home') }}images/app/twitter-card-api.png"/>
<meta property="og:url" content="{{ url('app::index') }}"/>
<meta property="og:image" content="{{ url('app::index') }}images/app/twitter-card-api.png"/>
<meta property="og:description"
content="An opinionated framework-less tool aimed at intermediate-to-advanced level programmers to start
implementing REST APIs swiftly and efficiently."/>
Expand Down
23 changes: 0 additions & 23 deletions src/App/templates/partial/alerts.html.twig

This file was deleted.

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
71 changes: 0 additions & 71 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
{
$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
Loading
Loading