Skip to content

Instantly share code, notes, and snippets.

@norberttech
Last active July 27, 2016 13:15
Show Gist options
  • Save norberttech/20e2263e2af5e5af6507 to your computer and use it in GitHub Desktop.
Save norberttech/20e2263e2af5e5af6507 to your computer and use it in GitHub Desktop.
TuTu as a dependency of application that use Symfony2 HttpKernel Component
{
"require": {
"stack/builder": "~1.0",
"stack/url-map": "~1.0"
},
"require-dev": {
"coduo/tutu-core": "1.0.*@dev"
},
}

This gist presents how to use TuTu as a dependency of Symfony2 application instead of using standalone TuTu application.

Lets assume that we have clean Symfony 2.3.* standard application.
We are going to use following libraries:

First we need to prepare configs for TuTu, lets create following folders structure in our application.

- app/  
- bin/ 
- src/
- tutu/
- - config/
- - - config.yml
- - - responses.yml
- - resources/
- vendor/
- web/ 
- - app_tutu.php
- compojser.json

Now you can run application using php build-in web server

$ php app/console server:run

When you open in your browser "http://localhost:8000/app_tutu.php/tutu/hello/world" you should see "Welcome in TuTu world!" message. Above technique can be used in any application that is based on Symfony Kernel.

Filenames in this gists use "_" character instead of "/" because of Github limitations.

parameters:
twig:
debug: true
auto_reload: true
hello_world_get:
request:
path: /app_tutu.php/tutu/hello/world
response:
content: >
Welcome in TuTu world!
<?php
use Symfony\Component\HttpFoundation\Request;
use Coduo\TuTu\Kernel;
use Coduo\TuTu\ServiceContainer;
use Symfony\Component\Debug\Debug;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
$container = new ServiceContainer();
$container->setParameter('tutu.root_path', realpath(__DIR__ . '/../tutu'));
$tutuKernel = new Kernel($container);
require_once __DIR__.'/../app/AppKernel.php';
$map = ["/tutu" => $tutuKernel];
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$kernel = (new Stack\Builder())
->push('Stack\UrlMap', $map)
->resolve($kernel);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment