Use with HttpKernel middlewares

Nice uses Symfony's HttpKernelInterface under the hood. This means that Nice is compatible with stack middlewares.

Add your favorite middlewares to your project:

php composer.phar require stack/builder:dev-master stack/run:dev-master

Then, in your front controller:

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
use Symfony\Component\HttpKernel\HttpCache\Store;
use Nice\Application;
use Nice\Router\RouteCollector;

require __DIR__ . '/../vendor/autoload.php';

// Create your app
$app = new Application();

// ..add your routes
$app->set('routes', function (RouteCollector $r) {
    // ...
});

// ..and then create the stack
$stack = new Stack\Builder();
$stack->push(function ($app) {
        return new HttpCache($app, new Store(__DIR__.'/cache'));
    });

$app = $stack->resolve($app);

// Run the app
Stack\run($app);

Custom Middlewares

Check out the Stack website for more information on custom middlewares.

Putting it all together

Now that we've seen how the basic parts of Nice work, we can put all the pieces together in a nice, maintainable application. Check out these additional notes on building great apps.


Powered by Codex 1.1.0