Coduo\TuTu\Kernel::handle PHP Method

handle() public method

public handle ( Request $request, integer $type = self::MASTER_REQUEST, boolean $catch = true ) : Response
$request Symfony\Component\HttpFoundation\Request
$type integer
$catch boolean
return Symfony\Component\HttpFoundation\Response
    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        try {
            $this->loadConfiguration();
            $request = $this->dispatchPreConfigResolveEvent($request);
            $configElement = $this->container->getService('response.config.resolver')->resolveConfigElement($request);
            if (isset($configElement)) {
                $this->dispatchRequestMatchEvent($configElement);
                return $this->container->getService('response.builder')->build($configElement, $request);
            }
            return $this->container->getService('response.builder')->buildForMismatch($request);
        } catch (\Exception $e) {
            return $this->container->getService('response.builder')->buildForException($e);
        }
    }

Usage Example

<?php

use Coduo\TuTu\Kernel;
use Coduo\TuTu\ServiceContainer;
use Symfony\Component\HttpFoundation\Request;
if (is_file($autoload = __DIR__ . '/../../vendor/autoload.php')) {
    require $autoload;
} else {
    header("Content-Type:text/plain");
    die('You must set up the project dependencies, run the following commands:' . PHP_EOL . 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . 'php composer.phar install' . PHP_EOL);
}
$container = new ServiceContainer();
$container->setParameter('tutu.root_path', realpath(__DIR__ . '/..'));
$kernel = new Kernel($container);
$request = Request::createFromGlobals();
$kernel->handle($request)->send();