Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Application.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace GitList;
  3. use Silex\Application as SilexApplication;
  4. use Silex\Provider\TwigServiceProvider;
  5. use Silex\Provider\UrlGeneratorServiceProvider;
  6. use GitList\Provider\GitServiceProvider;
  7. use GitList\Provider\RepositoryUtilServiceProvider;
  8. use GitList\Provider\ViewUtilServiceProvider;
  9. use GitList\Provider\RoutingUtilServiceProvider;
  10. /**
  11. * GitList application.
  12. */
  13. class Application extends SilexApplication
  14. {
  15. protected $path;
  16. /**
  17. * Constructor initialize services.
  18. *
  19. * @param Config $config
  20. * @param string $root Base path of the application files (views, cache)
  21. */
  22. public function __construct(Config $config, $root = null)
  23. {
  24. parent::__construct();
  25. $app = $this;
  26. $this->path = realpath($root);
  27. $this['debug'] = $config->get('app', 'debug');
  28. $this['filetypes'] = $config->getSection('filetypes');
  29. $this['cache.archives'] = $this->getCachePath() . 'archives';
  30. $this['path_prefix'] = '/'.$config->get('app', 'path_prefix');
  31. $this['clone_url'] = $config->get('app', 'clone_url');
  32. // Register services
  33. $this->register(new TwigServiceProvider(), array(
  34. 'twig.path' => $this->getViewPath(),
  35. 'twig.options' => $config->get('app', 'cache') ?
  36. array('cache' => $this->getCachePath() . 'views') : array(),
  37. ));
  38. $repositories = $config->get('git', 'repositories');
  39. $this->register(new GitServiceProvider(), array(
  40. 'git.client' => $config->get('git', 'client'),
  41. 'git.repos' => $repositories,
  42. 'ini.file' => "config.ini",
  43. 'git.hidden' => $config->get('git', 'hidden') ?
  44. $config->get('git', 'hidden') : array(),
  45. 'git.default_branch' => $config->get('git', 'default_branch') ?
  46. $config->get('git', 'default_branch') : 'master',
  47. ));
  48. $this->register(new ViewUtilServiceProvider());
  49. $this->register(new RepositoryUtilServiceProvider());
  50. $this->register(new UrlGeneratorServiceProvider());
  51. $this->register(new RoutingUtilServiceProvider());
  52. $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) {
  53. $twig->addFilter('htmlentities', new \Twig_Filter_Function('htmlentities'));
  54. $twig->addFilter('md5', new \Twig_Filter_Function('md5'));
  55. return $twig;
  56. }));
  57. // Handle errors
  58. $this->error(function (\Exception $e, $code) use ($app) {
  59. if ($app['debug']) {
  60. return;
  61. }
  62. return $app['twig']->render('error.twig', array(
  63. 'message' => $e->getMessage(),
  64. ));
  65. });
  66. }
  67. public function getPath()
  68. {
  69. return $this->path . DIRECTORY_SEPARATOR;
  70. }
  71. public function setPath($path)
  72. {
  73. $this->path = $path;
  74. return $this;
  75. }
  76. public function getCachePath()
  77. {
  78. return $this->path . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
  79. }
  80. public function getViewPath()
  81. {
  82. return $this->path . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR;
  83. }
  84. }