/** * Constructor initialize services. * * @param Config $config * @param string $root Base path of the application files (views, cache) */ public function __construct(Config $config, $root = null) { parent::__construct(); $app = $this; $root = realpath($root); $this['debug'] = $config->get('app', 'debug'); $this['filetypes'] = $config->getSection('filetypes'); $this['cache.archives'] = $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'archives'; // Register services $this->register(new TwigServiceProvider(), array('twig.path' => $root . DIRECTORY_SEPARATOR . 'views', 'twig.options' => array('cache' => $root . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'views'))); $this->register(new GitServiceProvider(), array('git.client' => $config->get('git', 'client'), 'git.repos' => $config->get('git', 'repositories'), 'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array())); $this->register(new ViewUtilServiceProvider()); $this->register(new RepositoryUtilServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) { $twig->addFilter('md5', new \Twig_Filter_Function('md5')); return $twig; })); // Handle errors $this->error(function (\Exception $e, $code) use($app) { if ($app['debug']) { return; } return $app['twig']->render('error.twig', array('message' => $e->getMessage())); }); }
/** * Constructor initialize services. * * @param Config $config * @param string $root Base path of the application files (views, cache) */ public function __construct(Config $config, $root = null) { parent::__construct(); $app = $this; $this->path = realpath($root); $this['debug'] = $config->get('app', 'debug'); $this['date.format'] = $config->get('date', 'format') ? $config->get('date', 'format') : 'd/m/Y H:i:s'; $this['theme'] = $config->get('app', 'theme') ? $config->get('app', 'theme') : 'default'; $this['title'] = $config->get('app', 'title') ? $config->get('app', 'title') : 'GitList'; $this['filetypes'] = $config->getSection('filetypes'); $this['binary_filetypes'] = $config->getSection('binary_filetypes'); $this['cache.archives'] = $this->getCachePath() . 'archives'; // Register services $this->register(new TwigServiceProvider(), array('twig.path' => array($this->getThemePath($this['theme']), $this->getThemePath('default')), 'twig.options' => $config->get('app', 'cache') ? array('cache' => $this->getCachePath() . 'views') : array())); $repositories = $config->get('git', 'repositories'); $this->register(new GitServiceProvider(), array('git.client' => $config->get('git', 'client'), 'git.repos' => $repositories, 'ini.file' => "config.ini", 'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array(), 'git.default_branch' => $config->get('git', 'default_branch') ? $config->get('git', 'default_branch') : 'master')); $this->register(new ViewUtilServiceProvider()); $this->register(new RepositoryUtilServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this->register(new RoutingUtilServiceProvider()); $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) { $twig->addFilter(new \Twig_SimpleFilter('htmlentities', 'htmlentities')); $twig->addFilter(new \Twig_SimpleFilter('md5', 'md5')); $twig->addFilter(new \Twig_SimpleFilter('format_date', array($app, 'formatDate'))); $twig->addFilter(new \Twig_SimpleFilter('format_size', array($app, 'formatSize'))); return $twig; })); $this['escaper.argument'] = $this->share(function () { return new Escaper\ArgumentEscaper(); }); // Handle errors $this->error(function (\Exception $e, $code) use($app) { if ($app['debug']) { return; } return $app['twig']->render('error.twig', array('message' => $e->getMessage())); }); $this->finish(function () use($app, $config) { if (!$config->get('app', 'cache')) { $fs = new Filesystem(); $fs->remove($app['cache.archives']); } }); }
/** * Constructor initialize services. * * @param Config $config * @param string $root Base path of the application files (views, cache) */ public function __construct(Config $config, $root = null) { parent::__construct(); $app = $this; $this->path = realpath($root); $this['debug'] = $config->get('app', 'debug'); $this['filetypes'] = $config->getSection('filetypes'); $this['cache.archives'] = $this->getCachePath() . 'archives'; $this['path_prefix'] = $config->get('app', 'path_prefix'); $this['clone_url'] = $config->get('app', 'clone_url'); // Register services $this->register(new TwigServiceProvider(), array('twig.path' => $this->getViewPath(), 'twig.options' => $config->get('app', 'cache') ? array('cache' => $this->getCachePath() . 'views') : array())); $repositories = $config->get('git', 'repositories'); $this->register(new GitServiceProvider(), array('git.client' => $config->get('git', 'client'), 'git.repos' => $repositories, 'ini.file' => "config.ini", 'git.hidden' => $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array(), 'git.default_branch' => $config->get('git', 'default_branch') ? $config->get('git', 'default_branch') : 'master')); $this->register(new ViewUtilServiceProvider()); $this->register(new RepositoryUtilServiceProvider()); $this->register(new UrlGeneratorServiceProvider()); $this->register(new RoutingUtilServiceProvider()); $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) { $twig->addFilter('htmlentities', new \Twig_Filter_Function('htmlentities')); $twig->addFilter('md5', new \Twig_Filter_Function('md5')); return $twig; })); // Handle errors $this->error(function (\Exception $e, $code) use($app) { if ($app['debug']) { return; } return $app['twig']->render('error.twig', array('message' => $e->getMessage())); }); }