thelia/thelia — pull request #777 by lunika (2014-10-06 20:30:34+00:00)
Title: [WIP] integrate Stack\Builder

This is a PoC integrating [stack](http://stackphp.com/) in Thelia.

A new tag is created : stack_middleware

If you want to add a new middleware in stack, your class must implement the HttpKernelInterface and had a constructor with at least 1 argument, the app's HttpKernel.

Here is a simple example :

Class :

```
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class Test implements HttpKernelInterface
{
/**
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $app;

public function __construct(HttpKernelInterface $app)
{
$this->app = $app;
}

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
return $this->app->handle($request, $type, $catch);
}
}
```

and the service definition

```

```

Here a more complete example. For our middleware, we need the event dispatcher :

```
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
* Class TestServices
* @package TestStack\Stack
* @author manuel raynaud
*/
class TestServices implements HttpKernelInterface
{
protected $app;

protected $dispatcher;

public function __construct(HttpKernelInterface $app, EventDispatcherInterface $dispatcher)
{
$this->app = $app;
$this->dispatcher = $dispatcher;
}

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
$this->dispatcher('event_name', new Event());
return $this->app->handle($request, $type, $catch);
}
}
```

and the service definition :

```

```