Minor fixes and path checks

This commit is contained in:
Klaus Silveira
2013-05-05 22:43:41 -03:00
parent f6852d2d83
commit 89bc96b4e0
2 changed files with 33 additions and 35 deletions

View File

@@ -4,32 +4,17 @@ if (!isset($config)) {
die("No configuration object provided.");
}
$repositories = $config->get('git', 'repositories');
if (!is_array($repositories)) {
# Convert the single item to an array - this is the internal handling
$repositories = array($repositories);
if (!is_writable(__DIR__ . DIRECTORY_SEPARATOR . 'cache')) {
die(sprintf('The "%s" folder must be writable for GitList to run.', __DIR__ . DIRECTORY_SEPARATOR . 'cache'));
}
$tmp_arr = array();
foreach ($repositories as $repo) {
$tmp = rtrim($repo, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$tmp_arr []= $tmp;
}
$repositories = $tmp_arr;
// Startup and configure Silex application
$app = new GitList\Application($config, __DIR__);
// Mount the controllers
$app->mount('', new GitList\Controller\MainController());
$app->mount('', new GitList\Controller\BlobController());
$app->mount('', new GitList\Controller\CommitController());
$app->mount('', new GitList\Controller\TreeController());
return $app;

View File

@@ -15,6 +15,8 @@ use GitList\Provider\RoutingUtilServiceProvider;
*/
class Application extends SilexApplication
{
protected $path;
/**
* Constructor initialize services.
*
@@ -24,44 +26,35 @@ class Application extends SilexApplication
public function __construct(Config $config, $root = null)
{
parent::__construct();
$app = $this;
$root = realpath($root);
$this->path = realpath($root);
$this['debug'] = $config->get('app', 'debug');
$this['filetypes'] = $config->getSection('filetypes');
$this['cache.archives'] = $root . DIRECTORY_SEPARATOR
. 'cache' . DIRECTORY_SEPARATOR . 'archives';
$this['cache.archives'] = $this->getCachePath() . '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'),
'twig.path' => $this->getViewPath(),
'twig.options' => array('cache' => $this->getCachePath() . 'views'),
));
$repositories = $config->get('git', 'repositories');
$cached_repos = $config->get('app', 'cached_repos');
if (false === $cached_repos || empty($cached_repos)) {
$cached_repos = $root . DIRECTORY_SEPARATOR . 'cache'
. DIRECTORY_SEPARATOR . 'repos.json';
$repositoryCache = $config->get('app', 'cached_repos');
if (false === $repositoryCache || empty($repositoryCache)) {
$repositoryCache = $this->getCachePath() . 'repos.json';
}
$this->register(new GitServiceProvider(), array(
'git.client' => $config->get('git', 'client'),
'git.repos' => $repositories,
'cache.repos' => $cached_repos,
'cache.repos' => $repositoryCache,
'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',
));
$cached_repos = $root . DIRECTORY_SEPARATOR .
'cache' . DIRECTORY_SEPARATOR . 'repos.json';
$this->register(new ViewUtilServiceProvider());
$this->register(new RepositoryUtilServiceProvider());
$this->register(new UrlGeneratorServiceProvider());
@@ -74,7 +67,6 @@ class Application extends SilexApplication
return $twig;
}));
// Handle errors
$this->error(function (\Exception $e, $code) use ($app) {
if ($app['debug']) {
@@ -86,5 +78,26 @@ class Application extends SilexApplication
));
});
}
public function getPath()
{
return $this->path . DIRECTORY_SEPARATOR;
}
public function setPath($path)
{
$this->path = $path;
return $this;
}
public function getCachePath()
{
return $this->path . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
}
public function getViewPath()
{
return $this->path . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR;
}
}