From 66ec944da1591489fb30c1570d391fc41a2471b9 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Sun, 15 Jul 2012 02:04:23 -0300 Subject: [PATCH] Trying to decouple the Git communication library from the GitList application as much as possible --- index.php | 2 +- lib/GitList/Component/Git/Client.php | 33 ++++++++++++++++----- lib/GitList/Provider/GitServiceProvider.php | 4 ++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index ce98b4e..a9d6bcd 100644 --- a/index.php +++ b/index.php @@ -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()); diff --git a/lib/GitList/Component/Git/Client.php b/lib/GitList/Component/Git/Client.php index 5b6c094..8d8b875 100644 --- a/lib/GitList/Component/Git/Client.php +++ b/lib/GitList/Component/Git/Client.php @@ -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; + } } diff --git a/lib/GitList/Provider/GitServiceProvider.php b/lib/GitList/Provider/GitServiceProvider.php index b1ef031..9fcafbd 100644 --- a/lib/GitList/Provider/GitServiceProvider.php +++ b/lib/GitList/Provider/GitServiceProvider.php @@ -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); }; }