From 7fe9182f11bec613d48f7bea32373cafc7ba56de Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Sun, 15 Jul 2012 00:32:24 -0300 Subject: [PATCH] Major refactoring of the application structure, mostly namespace changes and re-organization --- composer.json | 3 +- composer.lock | 2 +- controllers/archiveController.php | 36 ------- controllers/blobController.php | 32 ------- controllers/commitController.php | 59 ------------ controllers/indexController.php | 9 -- controllers/rssController.php | 16 ---- controllers/statsController.php | 19 ---- controllers/treeController.php | 43 --------- index.php | 19 ++-- lib/Application/UtilsServiceProvider.php | 25 ----- lib/{ => GitList/Component}/Git/Client.php | 2 +- .../Component}/Git/Commit/Author.php | 2 +- .../Component}/Git/Commit/Commit.php | 2 +- .../Component}/Git/Model/Blob.php | 8 +- .../Component}/Git/Model/Diff.php | 4 +- .../Component}/Git/Model/Line.php | 2 +- .../Component}/Git/Model/Symlink.php | 2 +- .../Component}/Git/Model/Tree.php | 8 +- .../Component}/Git/Repository.php | 10 +- .../Component}/Git/ScopeAware.php | 2 +- lib/GitList/Controller/BlobController.php | 49 ++++++++++ lib/GitList/Controller/CommitController.php | 76 +++++++++++++++ lib/GitList/Controller/MainController.php | 60 ++++++++++++ lib/GitList/Controller/TreeController.php | 93 +++++++++++++++++++ lib/GitList/Exception/BlankDataException.php | 5 + .../Provider}/GitServiceProvider.php | 3 +- .../RepositoryUtilServiceProvider.php | 26 ++++++ .../Provider/ViewUtilServiceProvider.php | 26 ++++++ .../Utils.php => GitList/Util/Repository.php} | 48 +--------- lib/GitList/Util/View.php | 47 ++++++++++ tests/ClientTest.php | 14 +-- 32 files changed, 423 insertions(+), 329 deletions(-) delete mode 100644 controllers/archiveController.php delete mode 100644 controllers/blobController.php delete mode 100644 controllers/commitController.php delete mode 100644 controllers/indexController.php delete mode 100644 controllers/rssController.php delete mode 100644 controllers/statsController.php delete mode 100644 controllers/treeController.php delete mode 100644 lib/Application/UtilsServiceProvider.php rename lib/{ => GitList/Component}/Git/Client.php (99%) rename lib/{ => GitList/Component}/Git/Commit/Author.php (92%) rename lib/{ => GitList/Component}/Git/Commit/Commit.php (98%) rename lib/{ => GitList/Component}/Git/Model/Blob.php (87%) rename lib/{ => GitList/Component}/Git/Model/Diff.php (91%) rename lib/{ => GitList/Component}/Git/Model/Line.php (95%) rename lib/{ => GitList/Component}/Git/Model/Symlink.php (93%) rename lib/{ => GitList/Component}/Git/Model/Tree.php (96%) rename lib/{ => GitList/Component}/Git/Repository.php (98%) rename lib/{ => GitList/Component}/Git/ScopeAware.php (92%) create mode 100644 lib/GitList/Controller/BlobController.php create mode 100644 lib/GitList/Controller/CommitController.php create mode 100644 lib/GitList/Controller/MainController.php create mode 100644 lib/GitList/Controller/TreeController.php create mode 100644 lib/GitList/Exception/BlankDataException.php rename lib/{Git => GitList/Provider}/GitServiceProvider.php (89%) create mode 100644 lib/GitList/Provider/RepositoryUtilServiceProvider.php create mode 100644 lib/GitList/Provider/ViewUtilServiceProvider.php rename lib/{Application/Utils.php => GitList/Util/Repository.php} (74%) create mode 100644 lib/GitList/Util/View.php diff --git a/composer.json b/composer.json index 53e89eb..0da1557 100644 --- a/composer.json +++ b/composer.json @@ -8,8 +8,7 @@ "minimum-stability": "dev", "autoload": { "psr-0": { - "Application": "lib/", - "Git": "lib/" + "GitList": "lib/" } } } diff --git a/composer.lock b/composer.lock index dbd4edf..1f4ae7c 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "b427463ed7f2ba35a378678440029596", + "hash": "c79508061cbc4f6754d227089129fa14", "packages": [ { "package": "pimple/pimple", diff --git a/controllers/archiveController.php b/controllers/archiveController.php deleted file mode 100644 index 0ac4992..0000000 --- a/controllers/archiveController.php +++ /dev/null @@ -1,36 +0,0 @@ -get('{repo}/{format}ball/{branch}', function($repo, $format, $branch) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $tree = $repository->getBranchTree($branch); - - if (false === $tree) { - return $app->abort(404, 'Invalid commit or tree reference: ' . $branch); - } - - $file = $app['cache.archives'] . DIRECTORY_SEPARATOR - . $repo . DIRECTORY_SEPARATOR - . substr($tree, 0, 2) . DIRECTORY_SEPARATOR - . substr($tree, 2) - . '.' - . $format; - - if (!file_exists($file)) { - $repository->createArchive($tree, $file, $format); - } - - return new StreamedResponse(function () use ($file) { - readfile($file); - }, 200, array( - 'Content-type' => ('zip' === $format) ? 'application/zip' : 'application/x-tar', - 'Content-Description' => 'File Transfer', - 'Content-Disposition' => 'attachment; filename="'.$repo.'-'.substr($tree, 0, 6).'.'.$format.'"', - 'Content-Transfer-Encoding' => 'binary', - 'Content-Length' => filesize($file), - )); -})->assert('format', '(zip|tar)') - ->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+') - ->bind('archive'); diff --git a/controllers/blobController.php b/controllers/blobController.php deleted file mode 100644 index 79d6632..0000000 --- a/controllers/blobController.php +++ /dev/null @@ -1,32 +0,0 @@ -get('{repo}/blob/{branch}/{file}', function($repo, $branch, $file) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $blob = $repository->getBlob("$branch:'$file'"); - $breadcrumbs = $app['utils']->getBreadcrumbs($file); - $fileType = $app['utils']->getFileType($file); - - return $app['twig']->render('file.twig', array( - 'file' => $file, - 'fileType' => $fileType, - 'blob' => $blob->output(), - 'repo' => $repo, - 'branch' => $branch, - 'breadcrumbs' => $breadcrumbs, - 'branches' => $repository->getBranches(), - 'tags' => $repository->getTags(), - )); -})->assert('file', '.+') - ->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+') - ->bind('blob'); - -$app->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $blob = $repository->getBlob("$branch:'$file'")->output(); - - return new Symfony\Component\HttpFoundation\Response($blob, 200, array('Content-Type' => 'text/plain')); -})->assert('file', '.+') - ->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+') - ->bind('blob_raw'); diff --git a/controllers/commitController.php b/controllers/commitController.php deleted file mode 100644 index f716921..0000000 --- a/controllers/commitController.php +++ /dev/null @@ -1,59 +0,0 @@ -get('{repo}/commits/{branch}/{file}', function($repo, $branch, $file) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $type = $file ? "$branch -- $file" : $branch; - $pager = $app['utils']->getPager($app['request']->get('page'), $repository->getTotalCommits($type)); - $commits = $repository->getCommits($type, $pager['current']); - - foreach ($commits as $commit) { - $date = $commit->getDate(); - $date = $date->format('m/d/Y'); - $categorized[$date][] = $commit; - } - - return $app['twig']->render('commits.twig', array( - 'pager' => $pager, - 'repo' => $repo, - 'branch' => $branch, - 'branches' => $repository->getBranches(), - 'tags' => $repository->getTags(), - 'commits' => $categorized, - 'file' => $file, - )); -})->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+') - ->assert('file', '.+') - ->value('branch', 'master') - ->value('file', '') - ->bind('commits'); - -$app->get('{repo}/commit/{commit}/', function($repo, $commit) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $commit = $repository->getCommit($commit); - - return $app['twig']->render('commit.twig', array( - 'branch' => 'master', - 'repo' => $repo, - 'commit' => $commit, - )); -})->assert('repo', '[\w-._]+') - ->assert('commit', '[a-f0-9]+') - ->bind('commit'); - -$app->get('{repo}/blame/{branch}/{file}', function($repo, $branch, $file) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $blames = $repository->getBlame("$branch -- $file"); - - return $app['twig']->render('blame.twig', array( - 'file' => $file, - 'repo' => $repo, - 'branch' => $branch, - 'branches' => $repository->getBranches(), - 'tags' => $repository->getTags(), - 'blames' => $blames, - )); -})->assert('repo', '[\w-._]+') - ->assert('file', '.+') - ->assert('branch', '[\w-._]+') - ->bind('blame'); diff --git a/controllers/indexController.php b/controllers/indexController.php deleted file mode 100644 index ba6c385..0000000 --- a/controllers/indexController.php +++ /dev/null @@ -1,9 +0,0 @@ -get('/', function() use ($app) { - $repositories = $app['git']->getRepositories($app['git.repos']); - - return $app['twig']->render('index.twig', array( - 'repositories' => $repositories, - )); -})->bind('homepage'); diff --git a/controllers/rssController.php b/controllers/rssController.php deleted file mode 100644 index 7f8be5b..0000000 --- a/controllers/rssController.php +++ /dev/null @@ -1,16 +0,0 @@ -get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $commits = $repository->getCommits($branch); - - $html = $app['twig']->render('rss.twig', array( - 'repo' => $repo, - 'branch' => $branch, - 'commits' => $commits, - )); - - return new Symfony\Component\HttpFoundation\Response($html, 200, array('Content-Type' => 'application/rss+xml')); -})->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+') - ->bind('rss'); diff --git a/controllers/statsController.php b/controllers/statsController.php deleted file mode 100644 index 7ac3707..0000000 --- a/controllers/statsController.php +++ /dev/null @@ -1,19 +0,0 @@ -get('{repo}/stats/{branch}', function($repo, $branch) use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $stats = $repository->getStatistics($branch); - $authors = $repository->getAuthorStatistics(); - - return $app['twig']->render('stats.twig', array( - 'repo' => $repo, - 'branch' => $branch, - 'branches' => $repository->getBranches(), - 'tags' => $repository->getTags(), - 'stats' => $stats, - 'authors' => $authors, - )); -})->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+') - ->value('branch', 'master') - ->bind('stats'); diff --git a/controllers/treeController.php b/controllers/treeController.php deleted file mode 100644 index fa544d1..0000000 --- a/controllers/treeController.php +++ /dev/null @@ -1,43 +0,0 @@ -get('{repo}/tree/{branch}/{tree}/', $treeController = function($repo, $branch = '', $tree = '') use ($app) { - $repository = $app['git']->getRepository($app['git.repos'] . $repo); - if (!$branch) { - $branch = $repository->getHead(); - } - $files = $repository->getTree($tree ? "$branch:'$tree'/" : $branch); - $breadcrumbs = $app['utils']->getBreadcrumbs($tree); - - $parent = null; - if (($slash = strrpos($tree, '/')) !== false) { - $parent = substr($tree, 0, $slash); - } elseif (!empty($tree)) { - $parent = ''; - } - - return $app['twig']->render('tree.twig', array( - 'files' => $files->output(), - 'repo' => $repo, - 'branch' => $branch, - 'path' => $tree ? $tree.'/' : $tree, - 'parent' => $parent, - 'breadcrumbs' => $breadcrumbs, - 'branches' => $repository->getBranches(), - 'tags' => $repository->getTags(), - 'readme' => $app['utils']->getReadme($repo, $branch), - )); -})->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+') - ->assert('tree', '.+') - ->bind('tree'); - -$app->get('{repo}/{branch}/', function($repo, $branch) use ($app, $treeController) { - return $treeController($repo, $branch); -})->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+') - ->bind('branch'); - -$app->get('{repo}/', function($repo) use ($app, $treeController) { - return $treeController($repo); -})->assert('repo', '[\w-._]+') - ->bind('repository'); diff --git a/index.php b/index.php index bf57caa..6618e3e 100644 --- a/index.php +++ b/index.php @@ -30,28 +30,23 @@ $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__.'/views', 'twig.options' => array('cache' => __DIR__.'/cache'), )); -$app->register(new Git\GitServiceProvider(), array( +$app->register(new GitList\Provider\GitServiceProvider(), array( 'git.client' => $config['git']['client'], 'git.repos' => $config['git']['repositories'], )); -$app->register(new Application\UtilsServiceProvider()); +$app->register(new GitList\Provider\ViewUtilServiceProvider()); +$app->register(new GitList\Provider\RepositoryUtilServiceProvider()); $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app['twig'] = $app->share($app->extend('twig', function($twig, $app) { - // Add the md5() function to Twig scope $twig->addFilter('md5', new Twig_Filter_Function('md5')); - return $twig; })); -// Load controllers -include 'controllers/archiveController.php'; -include 'controllers/indexController.php'; -include 'controllers/treeController.php'; -include 'controllers/blobController.php'; -include 'controllers/commitController.php'; -include 'controllers/statsController.php'; -include 'controllers/rssController.php'; +$app->mount('', new GitList\Controller\MainController()); +$app->mount('', new GitList\Controller\BlobController()); +$app->mount('', new GitList\Controller\CommitController()); +$app->mount('', new GitList\Controller\TreeController()); // Error handling $app->error(function (\Exception $e, $code) use ($app) { diff --git a/lib/Application/UtilsServiceProvider.php b/lib/Application/UtilsServiceProvider.php deleted file mode 100644 index 1f95412..0000000 --- a/lib/Application/UtilsServiceProvider.php +++ /dev/null @@ -1,25 +0,0 @@ -share(function () use ($app) { - return new Utils($app); - }); - } - - public function boot(Application $app) - { - } -} diff --git a/lib/Git/Client.php b/lib/GitList/Component/Git/Client.php similarity index 99% rename from lib/Git/Client.php rename to lib/GitList/Component/Git/Client.php index cd36b02..5b6c094 100644 --- a/lib/Git/Client.php +++ b/lib/GitList/Component/Git/Client.php @@ -1,6 +1,6 @@ get('{repo}/blob/{branch}/{file}', function($repo, $branch, $file) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $blob = $repository->getBlob("$branch:'$file'"); + $breadcrumbs = $app['util.view']->getBreadcrumbs($file); + $fileType = $app['util.repository']->getFileType($file); + + return $app['twig']->render('file.twig', array( + 'file' => $file, + 'fileType' => $fileType, + 'blob' => $blob->output(), + 'repo' => $repo, + 'branch' => $branch, + 'breadcrumbs' => $breadcrumbs, + 'branches' => $repository->getBranches(), + 'tags' => $repository->getTags(), + )); + })->assert('file', '.+') + ->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->bind('blob'); + + $route->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $blob = $repository->getBlob("$branch:'$file'")->output(); + + return new Response($blob, 200, array('Content-Type' => 'text/plain')); + })->assert('file', '.+') + ->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->bind('blob_raw'); + + return $route; + } +} \ No newline at end of file diff --git a/lib/GitList/Controller/CommitController.php b/lib/GitList/Controller/CommitController.php new file mode 100644 index 0000000..ead748f --- /dev/null +++ b/lib/GitList/Controller/CommitController.php @@ -0,0 +1,76 @@ +get('{repo}/commits/{branch}/{file}', function($repo, $branch, $file) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $type = $file ? "$branch -- $file" : $branch; + $pager = $app['util.view']->getPager($app['request']->get('page'), $repository->getTotalCommits($type)); + $commits = $repository->getCommits($type, $pager['current']); + + foreach ($commits as $commit) { + $date = $commit->getDate(); + $date = $date->format('m/d/Y'); + $categorized[$date][] = $commit; + } + + return $app['twig']->render('commits.twig', array( + 'pager' => $pager, + 'repo' => $repo, + 'branch' => $branch, + 'branches' => $repository->getBranches(), + 'tags' => $repository->getTags(), + 'commits' => $categorized, + 'file' => $file, + )); + })->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->assert('file', '.+') + ->value('branch', 'master') + ->value('file', '') + ->bind('commits'); + + $route->get('{repo}/commit/{commit}/', function($repo, $commit) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $commit = $repository->getCommit($commit); + + return $app['twig']->render('commit.twig', array( + 'branch' => 'master', + 'repo' => $repo, + 'commit' => $commit, + )); + })->assert('repo', '[\w-._]+') + ->assert('commit', '[a-f0-9]+') + ->bind('commit'); + + $route->get('{repo}/blame/{branch}/{file}', function($repo, $branch, $file) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $blames = $repository->getBlame("$branch -- $file"); + + return $app['twig']->render('blame.twig', array( + 'file' => $file, + 'repo' => $repo, + 'branch' => $branch, + 'branches' => $repository->getBranches(), + 'tags' => $repository->getTags(), + 'blames' => $blames, + )); + })->assert('repo', '[\w-._]+') + ->assert('file', '.+') + ->assert('branch', '[\w-._]+') + ->bind('blame'); + + return $route; + } +} \ No newline at end of file diff --git a/lib/GitList/Controller/MainController.php b/lib/GitList/Controller/MainController.php new file mode 100644 index 0000000..1c5b0dd --- /dev/null +++ b/lib/GitList/Controller/MainController.php @@ -0,0 +1,60 @@ +get('/', function() use ($app) { + $repositories = $app['git']->getRepositories($app['git.repos']); + + return $app['twig']->render('index.twig', array( + 'repositories' => $repositories, + )); + })->bind('homepage'); + + $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $stats = $repository->getStatistics($branch); + $authors = $repository->getAuthorStatistics(); + + return $app['twig']->render('stats.twig', array( + 'repo' => $repo, + 'branch' => $branch, + 'branches' => $repository->getBranches(), + 'tags' => $repository->getTags(), + 'stats' => $stats, + 'authors' => $authors, + )); + })->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->value('branch', 'master') + ->bind('stats'); + + $route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $commits = $repository->getCommits($branch); + + $html = $app['twig']->render('rss.twig', array( + 'repo' => $repo, + 'branch' => $branch, + 'commits' => $commits, + )); + + return new Response($html, 200, array('Content-Type' => 'application/rss+xml')); + })->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->bind('rss'); + + + return $route; + } +} \ No newline at end of file diff --git a/lib/GitList/Controller/TreeController.php b/lib/GitList/Controller/TreeController.php new file mode 100644 index 0000000..7cb8ba1 --- /dev/null +++ b/lib/GitList/Controller/TreeController.php @@ -0,0 +1,93 @@ +get('{repo}/tree/{branch}/{tree}/', $treeController = function($repo, $branch = '', $tree = '') use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + if (!$branch) { + $branch = $repository->getHead(); + } + $files = $repository->getTree($tree ? "$branch:'$tree'/" : $branch); + $breadcrumbs = $app['util.view']->getBreadcrumbs($tree); + + $parent = null; + if (($slash = strrpos($tree, '/')) !== false) { + $parent = substr($tree, 0, $slash); + } elseif (!empty($tree)) { + $parent = ''; + } + + return $app['twig']->render('tree.twig', array( + 'files' => $files->output(), + 'repo' => $repo, + 'branch' => $branch, + 'path' => $tree ? $tree . '/' : $tree, + 'parent' => $parent, + 'breadcrumbs' => $breadcrumbs, + 'branches' => $repository->getBranches(), + 'tags' => $repository->getTags(), + 'readme' => $app['util.repository']->getReadme($repo, $branch), + )); + })->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->assert('tree', '.+') + ->bind('tree'); + + $route->get('{repo}/{branch}/', function($repo, $branch) use ($app, $treeController) { + return $treeController($repo, $branch); + })->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->bind('branch'); + + $route->get('{repo}/', function($repo) use ($app, $treeController) { + return $treeController($repo); + })->assert('repo', '[\w-._]+') + ->bind('repository'); + + $route->get('{repo}/{format}ball/{branch}', function($repo, $format, $branch) use ($app) { + $repository = $app['git']->getRepository($app['git.repos'] . $repo); + $tree = $repository->getBranchTree($branch); + + if (false === $tree) { + return $app->abort(404, 'Invalid commit or tree reference: ' . $branch); + } + + $file = $app['cache.archives'] . DIRECTORY_SEPARATOR + . $repo . DIRECTORY_SEPARATOR + . substr($tree, 0, 2) . DIRECTORY_SEPARATOR + . substr($tree, 2) + . '.' + . $format; + + if (!file_exists($file)) { + $repository->createArchive($tree, $file, $format); + } + + return new StreamedResponse(function () use ($file) { + readfile($file); + }, 200, array( + 'Content-type' => ('zip' === $format) ? 'application/zip' : 'application/x-tar', + 'Content-Description' => 'File Transfer', + 'Content-Disposition' => 'attachment; filename="'.$repo.'-'.substr($tree, 0, 6).'.'.$format.'"', + 'Content-Transfer-Encoding' => 'binary', + )); + })->assert('format', '(zip|tar)') + ->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->bind('archive'); + + return $route; + } +} \ No newline at end of file diff --git a/lib/GitList/Exception/BlankDataException.php b/lib/GitList/Exception/BlankDataException.php new file mode 100644 index 0000000..a24670d --- /dev/null +++ b/lib/GitList/Exception/BlankDataException.php @@ -0,0 +1,5 @@ +share(function () use ($app) { + return new Repository($app); + }); + } + + public function boot(Application $app) + { + } +} diff --git a/lib/GitList/Provider/ViewUtilServiceProvider.php b/lib/GitList/Provider/ViewUtilServiceProvider.php new file mode 100644 index 0000000..87c5d00 --- /dev/null +++ b/lib/GitList/Provider/ViewUtilServiceProvider.php @@ -0,0 +1,26 @@ +share(function () { + return new View; + }); + } + + public function boot(Application $app) + { + } +} diff --git a/lib/Application/Utils.php b/lib/GitList/Util/Repository.php similarity index 74% rename from lib/Application/Utils.php rename to lib/GitList/Util/Repository.php index dd2f2f9..317ce8c 100644 --- a/lib/Application/Utils.php +++ b/lib/GitList/Util/Repository.php @@ -1,13 +1,10 @@ app = $app; } - /** - * Builds a breadcrumb array based on a path spec - * - * @param string $spec Path spec - * @return array Array with parts of the breadcrumb - */ - public function getBreadcrumbs($spec) - { - if (!$spec) { - return array(); - } - - $paths = explode('/', $spec); - - foreach ($paths as $i => $path) { - $breadcrumbs[] = array( - 'dir' => $path, - 'path' => implode('/', array_slice($paths, 0, $i + 1)), - ); - } - - return $breadcrumbs; - } - /** * Returns the file type based on filename by treating the extension * @@ -152,23 +125,6 @@ class Utils return 'text'; } - public function getPager($pageNumber, $totalCommits) - { - $pageNumber = (empty($pageNumber)) ? 0 : $pageNumber; - $lastPage = intval($totalCommits / 15); - // If total commits are integral multiple of 15, the lastPage will be commits/15 - 1. - $lastPage = ($lastPage * 15 == $totalCommits) ? $lastPage - 1 : $lastPage; - $nextPage = $pageNumber + 1; - $previousPage = $pageNumber - 1; - - return array('current' => $pageNumber, - 'next' => $nextPage, - 'previous' => $previousPage, - 'last' => $lastPage, - 'total' => $totalCommits, - ); - } - public function getReadme($repo, $branch = 'master') { $repository = $this->app['git']->getRepository($this->app['git.repos'] . $repo); diff --git a/lib/GitList/Util/View.php b/lib/GitList/Util/View.php new file mode 100644 index 0000000..e79970b --- /dev/null +++ b/lib/GitList/Util/View.php @@ -0,0 +1,47 @@ + $path) { + $breadcrumbs[] = array( + 'dir' => $path, + 'path' => implode('/', array_slice($paths, 0, $i + 1)), + ); + } + + return $breadcrumbs; + } + + public function getPager($pageNumber, $totalCommits) + { + $pageNumber = (empty($pageNumber)) ? 0 : $pageNumber; + $lastPage = intval($totalCommits / 15); + // If total commits are integral multiple of 15, the lastPage will be commits/15 - 1. + $lastPage = ($lastPage * 15 == $totalCommits) ? $lastPage - 1 : $lastPage; + $nextPage = $pageNumber + 1; + $previousPage = $pageNumber - 1; + + return array('current' => $pageNumber, + 'next' => $nextPage, + 'previous' => $previousPage, + 'last' => $lastPage, + 'total' => $totalCommits, + ); + } +} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index a548d62..bd068bb 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -2,8 +2,8 @@ require 'vendor/autoload.php'; -use Git\Client; -use Git\Repository; +use GitList\Component\Git\Client; +use GitList\Component\Git\Repository; use Symfony\Component\Filesystem\Filesystem; class ClientTest extends PHPUnit_Framework_TestCase @@ -181,9 +181,9 @@ class ClientTest extends PHPUnit_Framework_TestCase $commits = $repository->getCommits(); foreach ($commits as $commit) { - $this->assertInstanceOf('Git\Commit\Commit', $commit); + $this->assertInstanceOf('GitList\Component\Git\Commit\Commit', $commit); $this->assertTrue($commit->getMessage() === 'The truth unveiled'); - $this->assertInstanceOf('Git\Commit\Author', $commit->getAuthor()); + $this->assertInstanceOf('GitList\Component\Git\Commit\Author', $commit->getAuthor()); $this->assertEquals($commit->getAuthor()->getName(), 'Luke Skywalker'); $this->assertEquals($commit->getAuthor()->getEmail(), 'luke@rebel.org'); $this->assertEquals($commit->getCommiter()->getName(), 'Luke Skywalker'); @@ -206,9 +206,9 @@ class ClientTest extends PHPUnit_Framework_TestCase $commits = $repository->getCommits('test_file4.txt'); foreach ($commits as $commit) { - $this->assertInstanceOf('Git\Commit\Commit', $commit); + $this->assertInstanceOf('GitList\Component\Git\Commit\Commit', $commit); $this->assertTrue($commit->getMessage() === 'The truth unveiled'); - $this->assertInstanceOf('Git\Commit\Author', $commit->getAuthor()); + $this->assertInstanceOf('GitList\Component\Git\Commit\Author', $commit->getAuthor()); $this->assertEquals($commit->getAuthor()->getName(), 'Luke Skywalker'); $this->assertEquals($commit->getAuthor()->getEmail(), 'luke@rebel.org'); } @@ -220,7 +220,7 @@ class ClientTest extends PHPUnit_Framework_TestCase $files = $repository->getTree('master'); foreach ($files as $file) { - $this->assertInstanceOf('Git\Model\Blob', $file); + $this->assertInstanceOf('GitList\Component\Git\Model\Blob', $file); $this->assertRegExp('/test_file[0-9]*.txt/', $file->getName()); $this->assertEquals($file->getSize(), '55'); $this->assertEquals($file->getMode(), '100644');