Пример #1
0
use core\application\Errors;
use core\application\Application;
use core\application\Configurator;
$configurator = new Configurator($configurations);
$application = new Application($configurator->require('middleware', 'array'));
$errors = new Errors($errors);
use core\events\EventEmitter;
use core\application\Dispatcher;
$events = new EventEmitter();
$dispatcher = new Dispatcher();
$container->bind($events, \core\contracts\events\EventEmitterInterface::class);
$container->bind($errors, \core\contracts\errors\ErrorHandlerInterface::class);
$container->bind($configurator, \core\contracts\configurations\ConfiguratorInterface::class);
$request = core\http\request\Factory::build();
$response = core\http\response\Factory::build();
/**
 * @var \core\contracts\routing\Resolver $resolver
 */
$resolver = $container->create(core\contracts\routing\Resolver::class);
try {
    $application->bootstrap($container, $errors, $events, [$container, 'create']);
    $context = new \core\resources\ResourceContext($resolver->lookup($request->method(), $request->uri()->path()));
    $response = $application->dispatch($dispatcher, $request, $response, $context);
} catch (\Exception $exception) {
    if (!$errors->isCapable($exception)) {
        throw $exception;
    }
    $response = $errors->handle($exception, $response, [$container, 'call']);
}
$application->finish($response);