mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 19:20:56 +01:00
Trying to decouple the Git communication library from the GitList application as much as possible
This commit is contained in:
@@ -15,7 +15,6 @@ $config->set('git', 'repositories', rtrim($config->get('git', 'repositories'), D
|
||||
$app = new Silex\Application();
|
||||
$app['debug'] = $config->get('app', 'debug');
|
||||
$app['filetypes'] = $config->getSection('filetypes');
|
||||
$app['hidden'] = $config->get('git', 'hidden') ? $config->get('git', 'hidden') : array();
|
||||
$app['cache.archives'] = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'archives';
|
||||
|
||||
// Register services
|
||||
@@ -26,6 +25,7 @@ $app->register(new Silex\Provider\TwigServiceProvider(), array(
|
||||
$app->register(new GitList\Provider\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(),
|
||||
));
|
||||
$app->register(new GitList\Provider\ViewUtilServiceProvider());
|
||||
$app->register(new GitList\Provider\RepositoryUtilServiceProvider());
|
||||
|
||||
@@ -6,14 +6,13 @@ use Silex\Application;
|
||||
|
||||
class Client
|
||||
{
|
||||
protected $app;
|
||||
protected $path;
|
||||
protected $hidden;
|
||||
|
||||
public function __construct(Application $app)
|
||||
public function __construct($options = null)
|
||||
{
|
||||
$this->app = $app;
|
||||
$path = $this->app['git.client'] ? $this->app['git.client'] : '/usr/bin/git';
|
||||
$this->setPath($path);
|
||||
$this->setPath($options['path']);
|
||||
$this->setHidden($options['hidden']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +44,7 @@ class Client
|
||||
throw new \RuntimeException('There is no GIT repository at ' . $path);
|
||||
}
|
||||
|
||||
if (in_array($path, $this->app['hidden'])) {
|
||||
if (in_array($path, $this->getHidden())) {
|
||||
throw new \RuntimeException('You don\'t have access to this repository');
|
||||
}
|
||||
|
||||
@@ -91,7 +90,7 @@ class Client
|
||||
$isRepository = file_exists($file->getPathname() . '/.git/HEAD');
|
||||
|
||||
if ($isRepository || $isBare) {
|
||||
if (in_array($file->getPathname(), $this->app['hidden'])) {
|
||||
if (in_array($file->getPathname(), $this->getHidden())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -170,4 +169,24 @@ class Client
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hidden repository list
|
||||
*
|
||||
* @return array List of repositories to hide
|
||||
*/
|
||||
protected function getHidden()
|
||||
{
|
||||
return $this->hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the hidden repository list
|
||||
*
|
||||
* @param array $hidden List of repositories to hide
|
||||
*/
|
||||
protected function setHidden($hidden)
|
||||
{
|
||||
$this->hidden = $hidden;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@ class GitServiceProvider implements ServiceProviderInterface
|
||||
public function register(Application $app)
|
||||
{
|
||||
$app['git'] = function () use ($app) {
|
||||
return new Client($app);
|
||||
$options['path'] = $app['git.client'];
|
||||
$options['hidden'] = $app['git.hidden'];
|
||||
return new Client($options);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user