stackphp/builder — pull request #11 by igorw (2014-11-19 23:39:49+00:00)
Title: Build safe chain of terminable kernels (fixes #10)

* Should not call terminate() more than once (it was potentially factorial of stack size)
* Allow middlewares to delegate terminate() calls
* Increases stack size by number of non-terminable middlewares wrapping a terminable

If possible, we should find a way to reduce stack size, as it is expensive for GC.

Note: This implementation implicitly defines the semantics of Terminable to be as follows. A middleware that implements Terminable *must* always delegate to the next layer. If Terminable is not implemented, it will be wrapped in a StackedHttpKernel that handles the terminate() delegation. The delegation *must not* be conditional.

A consequence of this is that all middlewares will be called every time, each one exactly once.