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": { "require": {
"php": ">=8.3", "php": ">=8.2",
"ext-apcu": "*", "ext-apcu": "*",
"php-di/php-di": "^7.0.6", "php-di/php-di": "^7.0.1",
"nikic/fast-route": "^1.3", "nikic/fast-route": "^1.3",
"symfony/http-foundation": "^7.0" "symfony/http-foundation": "^6.2.5",
"vimeo/psalm": "^5.6"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "^1.10.46", "phpstan/phpstan": "^1.9.14",
"lubiana/code-quality": "^1.2", "lubiana/code-quality": "^1.1.5",
"phpstan/extension-installer": "^1.3.1", "phpstan/extension-installer": "^1.2",
"phpstan/phpstan-strict-rules": "^1.5.2", "phpstan/phpstan-strict-rules": "^1.4.5",
"thecodingmachine/phpstan-strict-rules": "^1.0", "thecodingmachine/phpstan-strict-rules": "^1.0",
"pmjones/php-styler": "^0.14.0", "pmjones/php-styler": "0.x-dev"
"vimeo/psalm": "^5.16"
}, },
"config": { "config": {
"allow-plugins": { "allow-plugins": {
@ -51,7 +51,7 @@
], ],
"style": "./vendor/bin/ecs", "style": "./vendor/bin/ecs",
"fix": [ "fix": [
"rector process", "php-styler apply" ,"ecs --fix", "ecs --fix" "rector process" ,"ecs --fix", "ecs --fix"
], ],
"rector": "./vendor/bin/rector process" "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; use PhpStyler\Styler;
return new Config( return new Config(
styler: new Styler(),
files: new Files(__DIR__ . '/src'), files: new Files(__DIR__ . '/src'),
styler: new Styler(),
cache: __DIR__ . '/.php-styler.cache', cache: __DIR__ . '/.php-styler.cache',
); );

View file

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <file src="src/Infrastructure/Finder.php">
<UnresolvableInclude> <UnresolvableInclude>
<code>require_once (string) $file</code> <code>require_once (string) $file</code>
</UnresolvableInclude> </UnresolvableInclude>
</file> </file>
<file src="src/Infrastructure/functions.php">
<MixedArgumentTypeCoercion>
<code>$callable</code>
</MixedArgumentTypeCoercion>
</file>
</files> </files>

View file

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

View file

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

View file

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

View file

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

View file

@ -15,7 +15,8 @@ final class Dispatcher
public function __construct( public function __construct(
private readonly InvokerInterface $invoker, private readonly InvokerInterface $invoker,
private array $listeners = [], private array $listeners = [],
) {} ) {
}
public function addListener(Listener $listener): void public function addListener(Listener $listener): void
{ {
@ -29,7 +30,7 @@ final class Dispatcher
{ {
return arrayFilter( return arrayFilter(
$this->listeners, $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); $filtered = $this->getListenerForEvent($event);
usort( usort(
$filtered, $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; return $filtered;
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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