} // IoC container setup $container = new \Illuminate\Container\Container(); // Application configuration $config = (include __BASE_DIR . 'app/config/config.php'); $config = new \App\Components\Config\Config($config); $container->instance('\\App\\Components\\Config\\Config', $config); $container->alias('\\App\\Components\\Config\\Config', 'config'); // Slim application setup $container->singleton('Slim\\Slim', function ($container) use($config) { $app = new \Slim\Slim(array('debug' => $config->get('app.debug'), 'mode' => $config->get('app.mode'), 'log.enabled' => $config->get('app.logging.enabled'), 'log.level' => $config->get('app.logging.level'), 'log.writer' => new \App\Components\Logging\FileSystemLogWriter(__BASE_DIR . 'app/storage/logs/' . date('ymd') . '.log'), 'templates.path' => __BASE_DIR . 'app/ressources/views', 'view' => new \Slim\Views\Twig())); // Twig template engine setup $app->view()->parserOptions = array('debug' => $config->get('app.debug'), 'cache' => __BASE_DIR . 'app/storage/cache/views'); $app->view()->parserExtensions = array(new \Slim\Views\TwigExtension()); // Laravel session component start and shutdown configuration $app->hook('slim.before', function ($container) use($container) { $container->make('session')->start(); }); $app->hook('slim.after.router', function ($container) use($container) { $container->make('session')->save(); }); return $app; }); $container->alias('Slim\\Slim', 'app'); // Setup router for simple controller routing $container->singleton('App\\Components\\Routing\\Router', function ($container) { $router = new \App\Components\Routing\Router($container->make('app'), $container); $router->setControllerNamespace('\\App\\Http\\Controllers'); return $router; }); $container->alias('App\\Components\\Routing\\Router', 'router'); // Filesystem access
$container = new Illuminate\Container\Container(); // Bind a "template" class to the container $container->bind('template', 'Acme\\Template'); // Bind a "mailer" class to the container // Use a callback to set additional settings $container->bind('mailer', function ($container) { $mailer = new Acme\Mailer(); $mailer->username = '******'; $mailer->password = '******'; $mailer->from = '*****@*****.**'; return $mailer; }); // Bind a shared "database" class to the container // Use a callback to set additional settings $container->singleton('database', function ($container) { return new Acme\Database('username', 'password', 'host', 'database'); }); // Bind an existing "authentication" class instance to the container $auth = new Acme\Authentication(); $container->instance('auth', $auth); /* |-------------------------------------------------------------------------- | Routes |-------------------------------------------------------------------------- */ $app = new \Slim\Slim(); $app->get('/', function () use($container) { // Create new Acme\Template instance $template = $container->make('template'); // Render template echo $template->render('home');
<?php use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/config.php'; $app = new Silex\Application(array('debug' => false)); /*** * * Let's configure the database we'll use through Mongovel * */ $container = new Illuminate\Container\Container(); $container->singleton('mongoveldb', function () { return new Mongovel\DB('mongodb://localhost', 'circular'); }); Mongovel\Mongovel::setContainer($container); /*** * * Let's group controllers on whether they're `public` or `protected` * */ $public = $app['controllers_factory']; $protected = $app['controllers_factory']; /*** * * Auth. * * Sample output: * array ( * 'id' => '507ed38198dee47b47000001',