diff --git a/src/Application.php b/src/Application.php index 4217d31..e35bd17 100644 --- a/src/Application.php +++ b/src/Application.php @@ -48,6 +48,9 @@ class Application extends SilexApplication )); $repositories = $config->get('git', 'repositories'); + $this['git.projects'] = $config->get('git', 'project_list') ? + $this->parseProjectList($config->get('git', 'project_list')) : + false; $this->register(new GitServiceProvider(), array( 'git.client' => $config->get('git', 'client'), @@ -153,4 +156,14 @@ class Application extends SilexApplication . 'twig' . DIRECTORY_SEPARATOR; } + + public function parseProjectList($project_list) + { + $projects = array(); + $file = fopen($project_list, "r"); + while ($file && !feof($file)) + $projects[] = trim(fgets($file)); + fclose($file); + return $projects; + } } diff --git a/src/Git/Client.php b/src/Git/Client.php index 56dbbbe..38db082 100644 --- a/src/Git/Client.php +++ b/src/Git/Client.php @@ -8,12 +8,14 @@ class Client extends BaseClient { protected $defaultBranch; protected $hidden; + protected $projects; public function __construct($options = null) { parent::__construct($options['path']); $this->setDefaultBranch($options['default_branch']); $this->setHidden($options['hidden']); + $this->setProjects($options['projects']); } public function getRepositoryFromName($paths, $repo) @@ -102,6 +104,10 @@ class Client extends BaseClient $repoName = $file->getFilename(); } + if (is_array($this->getProjects()) && !in_array($repoName, $this->getProjects())) { + continue; + } + $repositories[$repoName] = array( 'name' => $repoName, 'path' => $file->getPathname(), @@ -162,6 +168,28 @@ class Client extends BaseClient return $this; } + /** + * Get project list + * + * @return array List of repositories to show + */ + protected function getProjects() + { + return $this->projects; + } + + /** + * Set the shown repository list + * + * @param array $projects List of repositories to show + */ + protected function setProjects($projects) + { + $this->projects = $projects; + + return $this; + } + /** * Overloads the parent::createRepository method for the correct Repository class instance * diff --git a/src/Provider/GitServiceProvider.php b/src/Provider/GitServiceProvider.php index 44f2cfa..fd1da25 100644 --- a/src/Provider/GitServiceProvider.php +++ b/src/Provider/GitServiceProvider.php @@ -20,6 +20,7 @@ class GitServiceProvider implements ServiceProviderInterface $app['git'] = function () use ($app) { $options['path'] = $app['git.client']; $options['hidden'] = $app['git.hidden']; + $options['projects'] = $app['git.projects']; $options['ini.file'] = $app['ini.file']; $options['default_branch'] = $app['git.default_branch'];