34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Phred\Providers;
|
||
|
|
|
||
|
|
use DI\Container;
|
||
|
|
use DI\ContainerBuilder;
|
||
|
|
use Nyholm\Psr7\Factory\Psr17Factory;
|
||
|
|
use Phred\Http\Routing\RouteRegistry;
|
||
|
|
use Phred\Http\Router;
|
||
|
|
use Phred\Support\Contracts\ConfigInterface;
|
||
|
|
use Phred\Support\Contracts\ServiceProviderInterface;
|
||
|
|
|
||
|
|
final class AppServiceProvider implements ServiceProviderInterface
|
||
|
|
{
|
||
|
|
public function register(ContainerBuilder $builder, ConfigInterface $config): void
|
||
|
|
{
|
||
|
|
// Place app-specific bindings here as needed.
|
||
|
|
}
|
||
|
|
|
||
|
|
public function boot(Container $container): void
|
||
|
|
{
|
||
|
|
// Demonstrate adding a route from a provider
|
||
|
|
RouteRegistry::add(static function ($collector, Router $router): void {
|
||
|
|
$router->get('/_phred/app', static function () {
|
||
|
|
$psr17 = new Psr17Factory();
|
||
|
|
$res = $psr17->createResponse(200)->withHeader('Content-Type', 'application/json');
|
||
|
|
$res->getBody()->write(json_encode(['app' => true], JSON_UNESCAPED_SLASHES));
|
||
|
|
return $res;
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|