Example #1
0
$router = new Klein();
/*
 * Create new pimple container for dependency injection
 */
$app = new Container();
/*
 * Environment variables
 */
$app['config.storage'] = $config['DBFile'];
$app['twig'] = $twig;
/*
 * Build services and provide them from the Container
 */
$app['service.storage'] = function () use($app) {
    $service = new StorageService();
    $service->setStorageName($app['config.storage']);
    return $service;
};
$app['controller.data'] = function () use($app) {
    $controller = new DataController();
    $controller->setApp($app);
    $controller->setStorageService($app['service.storage']);
    return $controller;
};
/*
 * Build routes
 */
$router->respond('POST', '/update', function () use($app) {
    return $app['controller.data']->saveData($_POST['people']);
});
$router->respond('GET', '/show/[:id]', function ($request) use($app) {