Compare commits

..

No commits in common. "23d37db8f6a4a6846132d194391be1549b3a537c" and "f98fc5078d60293ea998143aca5f57697b37436d" have entirely different histories.

25 changed files with 1432 additions and 1418 deletions

View file

@ -1,32 +0,0 @@
on: [push]
jobs:
ls:
runs-on: docker
container:
image: git.php.fail/lubiana/container/php:8.3.0-node-20231212
steps:
- uses: actions/checkout@v3
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
id: restore-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: composer-cache
- run: composer install
- run: composer fix
- name: GIT commit and push all changed files
env:
CI_COMMIT_MESSAGE: Continuous Integration Fixes
CI_COMMIT_AUTHOR: Continuous Integration
run: |
if [[ -n "$(git status -s)" ]]; then
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "gitbot@users.noreply.php.fail"
git commit -am "${{ env.CI_COMMIT_MESSAGE }}"
git push
fi

View file

@ -15,20 +15,20 @@
}
],
"require": {
"php": ">=8.3",
"php": ">=8.2",
"ext-apcu": "*",
"php-di/php-di": "^7.0.6",
"php-di/php-di": "^7.0.1",
"nikic/fast-route": "^1.3",
"symfony/http-foundation": "^7.0"
"symfony/http-foundation": "^6.2.5",
"vimeo/psalm": "^5.6"
},
"require-dev": {
"phpstan/phpstan": "^1.10.46",
"lubiana/code-quality": "^1.2",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan-strict-rules": "^1.5.2",
"phpstan/phpstan": "^1.9.14",
"lubiana/code-quality": "^1.1.5",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan-strict-rules": "^1.4.5",
"thecodingmachine/phpstan-strict-rules": "^1.0",
"pmjones/php-styler": "^0.14.0",
"vimeo/psalm": "^5.16"
"pmjones/php-styler": "0.x-dev"
},
"config": {
"allow-plugins": {
@ -51,7 +51,7 @@
],
"style": "./vendor/bin/ecs",
"fix": [
"rector process", "php-styler apply" ,"ecs --fix", "ecs --fix"
"rector process" ,"ecs --fix", "ecs --fix"
],
"rector": "./vendor/bin/rector process"
},

2683
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@ use PhpStyler\Files;
use PhpStyler\Styler;
return new Config(
styler: new Styler(),
files: new Files(__DIR__ . '/src'),
styler: new Styler(),
cache: __DIR__ . '/.php-styler.cache',
);

View file

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.16.0@2897ba636551a8cb61601cc26f6ccfbba6c36591">
<files psalm-version="5.6.0@e784128902dfe01d489c4123d69918a9f3c1eac5">
<file src="src/Infrastructure/Finder.php">
<UnresolvableInclude>
<code>require_once (string) $file</code>
</UnresolvableInclude>
</file>
<file src="src/Infrastructure/functions.php">
<MixedArgumentTypeCoercion>
<code>$callable</code>
</MixedArgumentTypeCoercion>
</file>
</files>

View file

@ -6,7 +6,7 @@ use DI\ContainerBuilder;
use Lubian\AttributeMagic\Infrastructure\Event\Dispatcher;
use Lubian\AttributeMagic\Infrastructure\Event\DispatcherFactory;
use Lubian\AttributeMagic\Infrastructure\Finder;
use Lubian\AttributeMagic\Infrastructure\HttpKernel;
use Lubian\AttributeMagic\Infrastructure\WebApp\Request\RequestEvent;
use Lubian\AttributeMagic\Infrastructure\WebApp\Route\HandlerResolver;
use Symfony\Component\HttpFoundation\Request;
@ -14,17 +14,18 @@ use function assert;
require_once __DIR__ . '/../vendor/autoload.php';
$cached = false;
$container = (new ContainerBuilder())->addDefinitions(
$container = (new ContainerBuilder)->addDefinitions(
[
Finder::class => static fn(): Finder => new Finder(__DIR__, [], $cached),
Dispatcher::class => static fn(DispatcherFactory $f): Dispatcher
Finder::class => static fn (): Finder => new Finder(__DIR__, [], $cached),
Dispatcher::class => static fn (DispatcherFactory $f): Dispatcher
=> $f->getDispatcher($cached),
HandlerResolver::class => static fn(Dispatcher $d): HandlerResolver
HandlerResolver::class => static fn (Dispatcher $d): HandlerResolver
=> new HandlerResolver($d, $cached),
],
)->build();
$kernel = $container->get(HttpKernel::class);
assert($kernel instanceof HttpKernel);
$response = $kernel->handle(Request::createFromGlobals());
$response->send();
$dispatcher = $container->get(Dispatcher::class);
assert($dispatcher instanceof Dispatcher);
$request = new RequestEvent(Request::createFromGlobals());
$dispatcher->dispatch($request);
$request->response?->send();
exit();

View file

@ -9,11 +9,6 @@ use Symfony\Component\HttpFoundation\Response;
final class HalloDimi
{
/**
* Returns a JSON response with the message "Hallo Dimi".
*
* @return Response The JSON response.
*/
#[AsHandler(HttpMethod::GET, '/dimi')]
public function hallo(): Response
{

View file

@ -11,7 +11,8 @@ final readonly class Lol
{
public function __construct(
private Dispatcher $dispatcher
) {}
) {
}
#[AsHandler(HttpMethod::GET, '/')]
public function lol(): void

View file

@ -14,5 +14,6 @@ final readonly class AsListener
public function __construct(
public string $eventClass,
public int $priority = 0
) {}
) {
}
}

View file

@ -15,7 +15,8 @@ final class Dispatcher
public function __construct(
private readonly InvokerInterface $invoker,
private array $listeners = [],
) {}
) {
}
public function addListener(Listener $listener): void
{
@ -29,7 +30,7 @@ final class Dispatcher
{
return arrayFilter(
$this->listeners,
static fn(Listener $l): bool => $l->eventClass === $event::class,
static fn (Listener $l): bool => $l->eventClass === $event::class,
);
}
@ -41,7 +42,7 @@ final class Dispatcher
$filtered = $this->getListenerForEvent($event);
usort(
$filtered,
static fn(Listener $a, Listener $b): int => $a->priority <=> $b->priority,
static fn (Listener $a, Listener $b): int => $a->priority <=> $b->priority,
);
return $filtered;
}

View file

@ -18,7 +18,8 @@ final readonly class DispatcherFactory
public function __construct(
private Finder $finder,
private InvokerInterface $invoker,
) {}
) {
}
public function getDispatcher(bool $cached = false): Dispatcher
{

View file

@ -15,5 +15,6 @@ final readonly class Listener
public int $priority,
public string $listenerClass,
public string $listenerMethod,
) {}
) {
}
}

View file

@ -34,7 +34,8 @@ final class Finder
private readonly string $path,
private array $classNames = [],
private readonly bool $cached = false,
) {}
) {
}
/**
* @return Listener[]
@ -43,7 +44,7 @@ final class Finder
{
$this->populateClassnames();
return array_map(
static fn(array $h): Listener
static fn (array $h): Listener
=> new Listener($h[0]->eventClass, $h[0]->priority, $h[1], $h[2]),
iterator_to_array($this->getAttributes(AsListener::class)),
);
@ -56,7 +57,7 @@ final class Finder
{
$this->populateClassnames();
return array_map(
static fn(array $h): Handler
static fn (array $h): Handler
=> new Handler($h[0]->method, $h[0]->path, $h[1], $h[2]),
iterator_to_array($this->getAttributes(AsHandler::class)),
);
@ -71,7 +72,6 @@ final class Finder
if ($this->cached === true && file_exists(self::CACHE_FILE)) {
$data = file_get_contents(self::CACHE_FILE);
/** test */
if ($data === false) {
return;
}

View file

@ -1,23 +0,0 @@
<?php declare(strict_types=1);
namespace Lubian\AttributeMagic\Infrastructure;
use Exception;
use Lubian\AttributeMagic\Infrastructure\Event\Dispatcher;
use Lubian\AttributeMagic\Infrastructure\WebApp\Request\RequestEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class HttpKernel
{
public function __construct(
private readonly Dispatcher $dispatcher
) {}
public function handle(Request $request): Response
{
$requestEvent = new RequestEvent($request);
$this->dispatcher->dispatch($requestEvent);
return $requestEvent->response ?? throw new Exception('errror');
}
}

View file

@ -13,5 +13,6 @@ final readonly class AsHandler
public function __construct(
public HttpMethod $method,
public string $path
) {}
) {
}
}

View file

@ -13,5 +13,6 @@ final readonly class Handler
public string $path,
public string $handlerClass,
public string $handlerMethod,
) {}
) {
}
}

View file

@ -13,5 +13,6 @@ final class RequestEvent extends GenericEvent
public Request $request,
public Response|null $response = null,
public Handler|null $handler = null,
) {}
) {
}
}

View file

@ -9,7 +9,8 @@ final readonly class AttributeRouteCollector
{
public function __construct(
private Finder $finder
) {}
) {
}
#[AsListener(CollectRoutes::class)]
public function collect(CollectRoutes $event): void

View file

@ -32,6 +32,7 @@ final class CachedResponse
/** @var Response|null $response */
$response = unserialize($serialized);
$event->response = $response;
$event->stopped = true;
}

View file

@ -29,6 +29,7 @@ final class CachedRouteCollector
/** @var Handler[] $routes */
$routes = unserialize(file_get_contents(self::ROUTES_DIR));
$event->routes = $routes;
$event->stopped = true;
}

View file

@ -14,5 +14,6 @@ final class CollectRoutes extends GenericEvent
public function __construct(
public readonly bool $cached = false
) {}
) {
}
}

View file

@ -14,7 +14,8 @@ final readonly class HandlerCaller
{
public function __construct(
private InvokerInterface $invoker
) {}
) {
}
#[AsListener(RequestEvent::class, -50)]
public function callHandler(RequestEvent $event): void

View file

@ -21,7 +21,8 @@ final readonly class HandlerResolver
public function __construct(
private Dispatcher $dispatcher,
private bool $cached = false,
) {}
) {
}
#[AsListener(RequestEvent::class, -90)]
public function resolveHandler(RequestEvent $event): void

View file

@ -7,9 +7,9 @@ use function array_values;
/**
* @template T
* @param T[] $input
* @param callable(T):bool $callable
* @return T[]
* @param array<T> $input
* @param callable(mixed, mixed=):scalar $callable
* @return array<int, T>
*/
function arrayFilter(array $input, callable $callable): array
{

View file

@ -8,5 +8,6 @@ final class LauschEvent extends GenericEvent
{
public function __construct(
public string $message
) {}
) {
}
}