Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ARQUIVO ContainerConfig.php
- namespace Igor\Config;
- use Pimple\Container;
- /**
- * Configuração do container de dependências.
- */
- class ContainerConfig
- {
- /**
- *
- * @return \Pimple\Container
- */
- public static function getConfig()
- {
- $container = new Container();
- /**
- * Twig
- */
- // Template loader
- $container['twig_loader'] = function($c) {
- $cfg = TwigConfig::getConfig();
- return new \Twig_Loader_Filesystem($cfg['templates_path']);
- };
- // Instância compartilhada do Twig
- $container['twig'] = function($c) {
- $cfg = TwigConfig::getConfig();
- return new \Twig_Environment(
- $c['twig_loader'],
- $cfg['enviroment']
- );
- };
- // Factory do Twig
- $container['twig_factory'] = $container->factory(
- function ($c) {
- $cfg = TwigConfig::getConfig();
- return new \Twig_Environment(
- $c['twig_loader'],
- $cfg['enviroment']
- );
- }
- );
- /**
- * Request
- */
- $container['request'] = function ($c) {
- $cfg = MainConfig::getConfig();
- return new \Igor\Library\Http\Request(
- $cfg['request']['baseurl'],
- $cfg['request']['uri'],
- $cfg['request']['params']
- );
- };
- /**
- * Dispatcher
- */
- $container['dispatcher'] = function ($c) {
- return new \Igor\Library\Dispatcher();
- };
- /**
- * Response
- */
- $container['response'] = function ($c) {
- return new \Igor\Library\Http\Response();
- };
- /**
- * Router
- */
- $container['router'] = function ($c) {
- $cfg = RouterConfig::getConfig();
- return new \Igor\Library\Route\Router($cfg);
- };
- /**
- * Front controller
- */
- $container['front_controller'] = function ($c) {
- return new \Igor\Library\Controller\FrontController(
- $c['router'], $c['dispatcher']
- );
- };
- return $container;
- }
- }
- // ARQUIVO index.php
- require 'vendor/autoload.php';
- use Igor\Config\ContainerConfig;
- // O controller envia saída direto para o browser, então o Output Buffer deve
- // ser ativado para que seja possível enviar enviar os cabeçalhos de resposta
- // no final da execução da aplicação.
- ob_start();
- $container = ContainerConfig::getConfig();
- $request = $container['request'];
- $response = $container['response'];
- $frontController = $container['front_controller'];
- $frontController->run($request, $response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement