Skip to content

Commit 9c323fc

Browse files
Koldo Picazakpicaza
authored andcommitted
update deps
1 parent 3ac5442 commit 9c323fc

File tree

10 files changed

+106
-42
lines changed

10 files changed

+106
-42
lines changed

composer.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^7.3",
18+
"php": "^7.4|^8.0",
1919
"ext-json": "*",
20-
"antidot-fw/antidot-react-http": "dev-master",
21-
"antidot-fw/antidot-react-psr15": "dev-master",
20+
"antidot-fw/react-framework": "^1.0.0",
2221
"antidot-fw/fast-router-adapter": "^0.1.0",
2322
"antidot-fw/cli": "^1.1.0",
2423
"antidot-fw/container": "^0.1.0",
@@ -32,11 +31,10 @@
3231
"wshafer/psr11-monolog": "^3.0.0|@dev"
3332
},
3433
"require-dev": {
35-
"blackfire/php-sdk": "^1.20",
3634
"franzl/whoops-middleware": "^1.1",
3735
"phpro/grumphp": "^1.0",
38-
"phpstan/phpstan": "^0.11.5",
39-
"phpunit/phpunit": "^8.0",
36+
"phpstan/phpstan": "^0.12",
37+
"phpunit/phpunit": "^8.0|^9.0",
4038
"roave/security-advisories": "dev-master",
4139
"seregazhuk/php-watcher": "^0.5.1",
4240
"squizlabs/php_codesniffer": "^3.4",
@@ -75,15 +73,14 @@
7573
"antidot-fw/logger",
7674
"antidot-fw/dev-tools",
7775
"antidot-fw/doctrine",
78-
"antidot-fw/session",
79-
"antidot-fw/aura-router-adapter",
76+
"antidot-fw/dbal-adapter",
77+
"antidot-fw/tactician-adapter",
78+
"antidot-fw/message-queue",
8079
"antidot-fw/cli",
8180
"antidot-fw/fast-router-adapter",
82-
"antidot-fw/phug-te,plate-renderer",
8381
"antidot-fw/event-dispatcher",
8482
"antidot-fw/symfony-config-translator",
8583
"wshafer/psr11-monolog",
86-
"laminias/laminas-httphandlerrunner",
8784
"antidot-fw/antidot-react-http",
8885
"antidot-fw/antidot-react-psr15"
8986
]

config/config.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
\Antidot\Logger\Container\Config\ConfigProvider::class,
2121
\Antidot\Cli\Container\Config\ConfigProvider::class,
2222
\Antidot\Fast\Router\Container\Config\ConfigProvider::class,
23-
\Antidot\React\PSR15\Container\Config\ConfigProvider::class,
2423
\Antidot\Container\Config\ConfigProvider::class,
25-
\Laminas\HttpHandlerRunner\ConfigProvider::class,
2624
\Antidot\React\Container\Config\ConfigProvider::class,
2725
class_exists(DevToolsConfigProvider::class) ? DevToolsConfigProvider::class : fn() => [],
2826
// Load application config in a pre-defined order in such a way that local settings

config/services/dependencies.prod.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
services:
22
App\Application\Http\Handler\HomePage:
3+
App\Application\Http\Middleware\HelloWorld:
34
# App\Application\Http\Handler\SomeTestClass:
45
# arguments:
56
# $dispatcher: '@another.dispatcher'

grumphp.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ grumphp:
66
script: check-all
77
triggered_by: [php, phtml]
88
working_directory: ~
9+

public/index.php

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,69 @@
1+
#!/usr/bin/env php
12
<?php
23

34
declare(strict_types=1);
45

5-
// Delegate static file requests back to the PHP built-in webserver
66
use Antidot\Application\Http\Application;
7+
use Antidot\React\PromiseResponse;
8+
use Laminas\Diactoros\Response\HtmlResponse;
9+
use Psr\Http\Message\ServerRequestInterface;
10+
use Ramsey\Uuid\Uuid;
11+
use React\EventLoop\Factory;
12+
use React\Http\Middleware\LimitConcurrentRequestsMiddleware;
13+
use React\Http\Middleware\RequestBodyBufferMiddleware;
14+
use React\Http\Middleware\RequestBodyParserMiddleware;
15+
use React\Http\Middleware\StreamingRequestMiddleware;
16+
use React\Http\Server;
17+
use React\Socket\Server as Socket;
18+
use function React\Promise\resolve;
719

8-
if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) {
9-
return false;
10-
}
11-
\chdir(\dirname(__DIR__));
1220
require 'vendor/autoload.php';
13-
/**
14-
* Self-called anonymous function that creates its own scope and keep the global namespace clean.
15-
*/
16-
\call_user_func(static function (): void {
17-
error_reporting(E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
1821

19-
/** @var \Psr\Container\ContainerInterface $container */
22+
call_user_func(static function () {
23+
$loop = Factory::create();
2024
$container = require 'config/container.php';
21-
/** @var Application $app */
22-
$app = $container->get(Application::class);
23-
// Execute programmatic/declarative middleware pipeline and routing
24-
// configuration statements
25-
(require 'router/middleware.php')($app, $container);
26-
(require 'router/routes.php')($app, $container);
27-
$app->run();
25+
$application = $container->get(Application::class);
26+
(require 'router/middleware.php')($application, $container);
27+
(require 'router/routes.php')($application, $container);
28+
29+
$server = new Server(
30+
$loop,
31+
new StreamingRequestMiddleware(),
32+
new LimitConcurrentRequestsMiddleware(100), // 100 concurrent buffering handlers
33+
new RequestBodyBufferMiddleware(4 * 1024 * 1024), // 4 MiB
34+
new RequestBodyParserMiddleware(),
35+
static function (ServerRequestInterface $request) use ($application) {
36+
try {
37+
$response = new PromiseResponse(
38+
resolve($request)
39+
->then(static fn ($request) => $request->withAttribute('request_id', Uuid::uuid4()->toString()))
40+
->then(static fn ($request) => $application->handle($request))
41+
);
42+
} catch (Throwable $exception) {
43+
if (!empty($e = $exception->getPrevious())) {
44+
$exception = $e;
45+
}
46+
47+
$response = new HtmlResponse(
48+
sprintf(
49+
'%s in file %s in line %s.',
50+
$exception->getMessage(),
51+
$exception->getFile(),
52+
$exception->getLine()
53+
)
54+
);
55+
}
56+
57+
return resolve($response);
58+
}
59+
);
60+
61+
$server->on('error', function ($err) {
62+
dump($err);
63+
});
64+
65+
$socket = new Socket('0.0.0.0:8080', $loop);
66+
$server->listen($socket);
67+
68+
$loop->run();
2869
});

router/middleware.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
declare(strict_types=1);
44

55
use Antidot\Application\Http\Application;
6-
use Antidot\React\PSR15\Middleware\ErrorMiddleware;
7-
use Antidot\React\PSR15\Middleware\ExceptionLoggerMiddleware;
8-
use Antidot\React\PSR15\Middleware\RequestLoggerMiddleware;
9-
use Antidot\React\PSR15\Middleware\RouteDispatcherMiddleware;
10-
use Antidot\React\PSR15\Middleware\RouteNotFoundMiddleware;
6+
use Antidot\Application\Http\Middleware\ErrorMiddleware;
7+
use Antidot\Application\Http\Middleware\RouteDispatcherMiddleware;
8+
use Antidot\Application\Http\Middleware\RouteNotFoundMiddleware;
9+
use Antidot\Logger\Application\Http\Middleware\ExceptionLoggerMiddleware;
10+
use Antidot\Logger\Application\Http\Middleware\RequestLoggerMiddleware;
1111

12-
return static function (Application $app) : void {
12+
return static function (Application $app): void {
1313
$app->pipe(ErrorMiddleware::class);
1414
$app->pipe(ExceptionLoggerMiddleware::class);
1515
$app->pipe(RequestLoggerMiddleware::class);

router/routes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Antidot\Application\Http\Application;
66
use App\Application\Http\Handler\HomePage;
7+
use App\Application\Http\Middleware\HelloWorld;
78
use Psr\Container\ContainerInterface;
89

910
/**
@@ -20,5 +21,5 @@
2021
* $app->route('/contact', App\Handler\ContactHandler::class, ['GET', 'POST', ...], 'contact');
2122
*/
2223
return static function (Application $app, ContainerInterface $container) : void {
23-
$app->get('/', [HomePage::class], 'home');
24+
$app->get('/', [HelloWorld::class, HomePage::class], 'home');
2425
};

src/Application/Command/SomeCommandExample.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
class SomeCommandExample extends Command
1212
{
13-
protected function configure()
13+
protected function configure(): void
1414
{
1515
$this->setName('my:custom:command');
1616
}
1717

18-
protected function execute(InputInterface $input, OutputInterface $output)
18+
protected function execute(InputInterface $input, OutputInterface $output): int
1919
{
20+
return 0;
2021
}
2122
}

src/Application/Http/Handler/HomePage.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace App\Application\Http\Handler;
66

7-
use Antidot\React\PSR15\Response\PromiseResponse;
7+
use Antidot\React\PromiseResponse;
88
use App\Application\Event\SomeEvent;
9+
use Laminas\Diactoros\Response\JsonResponse;
910
use Psr\EventDispatcher\EventDispatcherInterface;
1011
use Psr\Http\Message\ResponseInterface;
1112
use Psr\Http\Message\ServerRequestInterface;
1213
use Psr\Http\Server\RequestHandlerInterface;
13-
use Zend\Diactoros\Response\JsonResponse;
1414

1515
use function React\Promise\resolve;
1616

@@ -35,7 +35,10 @@ public function handle(ServerRequestInterface $request): ResponseInterface
3535
->then(static function (ServerRequestInterface $request) {
3636
return new JsonResponse([
3737
'docs' => 'https://antidotfw.io',
38-
'message' => $request->getAttribute('foo') . ' Welcome to Antidot Framework Starter',
38+
'message' => sprintf(
39+
'Hello %s!!!! Welcome to Antidot Framework Starter',
40+
$request->getAttribute('greet')
41+
)
3942
]);
4043
})
4144
);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Application\Http\Middleware;
6+
7+
use Psr\Http\Message\ResponseInterface;
8+
use Psr\Http\Message\ServerRequestInterface;
9+
use Psr\Http\Server\MiddlewareInterface;
10+
use Psr\Http\Server\RequestHandlerInterface;
11+
12+
class HelloWorld implements MiddlewareInterface
13+
{
14+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
15+
{
16+
$greet = $request->getQueryParams()['greet'] ?? 'World';
17+
$request = $request->withAttribute('greet', $greet);
18+
19+
return $handler->handle($request);
20+
}
21+
}

0 commit comments

Comments
 (0)