<?php
declare(strict_types=1);
namespace App\Application\Http\Handler;
use App\Application\Event\SomeEvent;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Laminas\Diactoros\Response\JsonResponse;
class ApiPage implements RequestHandlerInterface
{
/** @var EventDispatcherInterface */
private $eventDispatcher;
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->eventDispatcher->dispatch(SomeEvent::occur());
return new JsonResponse([
'docs' => 'https://antidotfw.io',
'Message' => 'Welcome to Antidot Framework Starter'
]);
}
}
services:
App\Application\Http\Handler\HomePage:
App\Application\Http\Handler\ApiPage:
App\Application\Http\Handler\SomeMiddleware:
App\Application\EventListener\SomeEventListener:
tags:
- { name: 'event_listener', event: 'App\Application\Event\SomeEvent' }
some.command:
class: App\Application\Command\SomeCommandExample
tags:
- { name: 'console.command', command: 'my:custom:command' }
parameters:
debug: true
config_cache_enabled: false
monolog:
handlers:
default:
type: 'stream'
options:
stream: 'var/log/%date%-default.log'
level: 400
<?php
declare(strict_types=1);
use Antidot\Application\Http\Application;
use App\Application\Http\Handler\HomePage;
use App\Application\Http\Handler\ApiPage;
use App\Application\Http\Handler\SomeMiddleware;
use Psr\Container\ContainerInterface;
/**
* Setup routes with a single request method:
*
* $app->get('/', App\Handler\HomePageHandler::class, 'home');
* $app->post('/album', App\Handler\AlbumCreateHandler::class, 'album.create');
* $app->put('/album/:id', App\Handler\AlbumUpdateHandler::class, 'album.put');
* $app->patch('/album/:id', App\Handler\AlbumUpdateHandler::class, 'album.patch');
* $app->delete('/album/:id', App\Handler\AlbumDeleteHandler::class, 'album.delete');
*
* Or with multiple request methods:
*
* $app->route('/contact', App\Handler\ContactHandler::class, ['GET', 'POST', ...], 'contact');
*/
return static function (Application $app, ContainerInterface $container) : void {
$app->get('/', [SomeMiddleware::class, HomePage::class], 'home');
$app->get('/api', [SomeMiddleware::class, ApiPage::class], 'api');
};