Major refactoring of the application structure, mostly namespace changes and re-organization

This commit is contained in:
Klaus Silveira
2012-07-15 00:32:24 -03:00
parent ffcf6081ac
commit 7fe9182f11
32 changed files with 423 additions and 329 deletions

View File

@@ -8,8 +8,7 @@
"minimum-stability": "dev",
"autoload": {
"psr-0": {
"Application": "lib/",
"Git": "lib/"
"GitList": "lib/"
}
}
}

2
composer.lock generated
View File

@@ -1,5 +1,5 @@
{
"hash": "b427463ed7f2ba35a378678440029596",
"hash": "c79508061cbc4f6754d227089129fa14",
"packages": [
{
"package": "pimple/pimple",

View File

@@ -1,36 +0,0 @@
<?php
use Symfony\Component\HttpFoundation\StreamedResponse;
$app->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');

View File

@@ -1,32 +0,0 @@
<?php
$app->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');

View File

@@ -1,59 +0,0 @@
<?php
$app->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');

View File

@@ -1,9 +0,0 @@
<?php
$app->get('/', function() use ($app) {
$repositories = $app['git']->getRepositories($app['git.repos']);
return $app['twig']->render('index.twig', array(
'repositories' => $repositories,
));
})->bind('homepage');

View File

@@ -1,16 +0,0 @@
<?php
$app->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');

View File

@@ -1,19 +0,0 @@
<?php
$app->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');

View File

@@ -1,43 +0,0 @@
<?php
$app->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');

View File

@@ -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) {

View File

@@ -1,25 +0,0 @@
<?php
namespace Application;
use Silex\Application;
use Silex\ServiceProviderInterface;
class UtilsServiceProvider implements ServiceProviderInterface
{
/**
* Register the Utils class on the Application ServiceProvider
*
* @param Application $app Silex Application
*/
public function register(Application $app)
{
$app['utils'] = $app->share(function () use ($app) {
return new Utils($app);
});
}
public function boot(Application $app)
{
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace Git;
namespace GitList\Component\Git;
use Silex\Application;

View File

@@ -1,6 +1,6 @@
<?php
namespace Git\Commit;
namespace GitList\Component\Git\Commit;
class Author
{

View File

@@ -1,6 +1,6 @@
<?php
namespace Git\Commit;
namespace GitList\Component\Git\Commit;
class Commit
{

View File

@@ -1,10 +1,10 @@
<?php
namespace Git\Model;
namespace GitList\Component\Git\Model;
use Git\Client;
use Git\Repository;
use Git\ScopeAware;
use GitList\Component\Git\Client;
use GitList\Component\Git\Repository;
use GitList\Component\Git\ScopeAware;
class Blob extends ScopeAware
{

View File

@@ -1,8 +1,8 @@
<?php
namespace Git\Model;
namespace GitList\Component\Git\Model;
use Git\Model\Line;
use GitList\Component\Git\Model\Line;
class Diff
{

View File

@@ -1,6 +1,6 @@
<?php
namespace Git\Model;
namespace GitList\Component\Git\Model;
class Line
{

View File

@@ -1,6 +1,6 @@
<?php
namespace Git\Model;
namespace GitList\Component\Git\Model;
class Symlink
{

View File

@@ -1,10 +1,10 @@
<?php
namespace Git\Model;
namespace GitList\Component\Git\Model;
use Git\Client;
use Git\Repository;
use Git\ScopeAware;
use GitList\Component\Git\Client;
use GitList\Component\Git\Repository;
use GitList\Component\Git\ScopeAware;
class Tree extends ScopeAware implements \RecursiveIterator
{

View File

@@ -1,11 +1,11 @@
<?php
namespace Git;
namespace GitList\Component\Git;
use Git\Commit\Commit;
use Git\Model\Tree;
use Git\Model\Blob;
use Git\Model\Diff;
use GitList\Component\Git\Commit\Commit;
use GitList\Component\Git\Model\Tree;
use GitList\Component\Git\Model\Blob;
use GitList\Component\Git\Model\Diff;
use Symfony\Component\Filesystem\Filesystem;
class Repository

View File

@@ -1,6 +1,6 @@
<?php
namespace Git;
namespace GitList\Component\Git;
class ScopeAware
{

View File

@@ -0,0 +1,49 @@
<?php
namespace GitList\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Response;
class BlobController implements ControllerProviderInterface
{
public function connect(Application $app)
{
$route = $app['controllers_factory'];
$route->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;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace GitList\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Response;
class CommitController implements ControllerProviderInterface
{
public function connect(Application $app)
{
$route = $app['controllers_factory'];
$route->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;
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace GitList\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Response;
class MainController implements ControllerProviderInterface
{
public function connect(Application $app)
{
$route = $app['controllers_factory'];
$route->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;
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace GitList\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
class TreeController implements ControllerProviderInterface
{
public function connect(Application $app)
{
$route = $app['controllers_factory'];
$route->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;
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace GitList\Exception;
class BlankDataException extends \RuntimeException {}

View File

@@ -1,7 +1,8 @@
<?php
namespace Git;
namespace GitList\Provider;
use GitList\Component\Git\Client;
use Silex\Application;
use Silex\ServiceProviderInterface;

View File

@@ -0,0 +1,26 @@
<?php
namespace GitList\Provider;
use GitList\Util\Repository;
use Silex\Application;
use Silex\ServiceProviderInterface;
class RepositoryUtilServiceProvider implements ServiceProviderInterface
{
/**
* Register the Util\Repository class on the Application ServiceProvider
*
* @param Application $app Silex Application
*/
public function register(Application $app)
{
$app['util.repository'] = $app->share(function () use ($app) {
return new Repository($app);
});
}
public function boot(Application $app)
{
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace GitList\Provider;
use GitList\Util\View;
use Silex\Application;
use Silex\ServiceProviderInterface;
class ViewUtilServiceProvider implements ServiceProviderInterface
{
/**
* Register the Util\Interface class on the Application ServiceProvider
*
* @param Application $app Silex Application
*/
public function register(Application $app)
{
$app['util.view'] = $app->share(function () {
return new View;
});
}
public function boot(Application $app)
{
}
}

View File

@@ -1,13 +1,10 @@
<?php
namespace Application;
namespace GitList\Util;
use Silex\Application;
/**
* General helper class, mostly used for string parsing inside the application controllers
*/
class Utils
class Repository
{
protected $app;
@@ -98,30 +95,6 @@ class Utils
$this->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);

47
lib/GitList/Util/View.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
namespace GitList\Util;
class View
{
/**
* 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;
}
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,
);
}
}

View File

@@ -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');