Teknik is a suite of services with attractive and functional interfaces. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainController.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace GitList\Controller;
  3. use Silex\Application;
  4. use Silex\ControllerProviderInterface;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\HttpFoundation\Request;
  7. class MainController implements ControllerProviderInterface
  8. {
  9. public function connect(Application $app)
  10. {
  11. $route = $app['controllers_factory'];
  12. $route->get('/', function() use ($app) {
  13. $repositories = $app['git']->getRepositories($app['git.repos']);
  14. return $app['twig']->render('index.twig', array(
  15. 'repositories' => $repositories,
  16. ));
  17. })->bind('homepage');
  18. $route->get('/refresh', function(Request $request) use ($app ) {
  19. # Go back to calling page
  20. return $app->redirect($request->headers->get('Referer'));
  21. })->bind('refresh');
  22. $route->get('{repo}/stats/{branch}', function($repo, $branch) use ($app) {
  23. $repository = $app['git']->getRepositoryFromName($app['git.repos'], $repo);
  24. if ($branch === null) {
  25. $branch = $repository->getHead();
  26. }
  27. $stats = $repository->getStatistics($branch);
  28. $authors = $repository->getAuthorStatistics($branch);
  29. return $app['twig']->render('stats.twig', array(
  30. 'repo' => $repo,
  31. 'branch' => $branch,
  32. 'branches' => $repository->getBranches(),
  33. 'tags' => $repository->getTags(),
  34. 'stats' => $stats,
  35. 'authors' => $authors,
  36. ));
  37. })->assert('repo', $app['util.routing']->getRepositoryRegex())
  38. ->assert('branch', $app['util.routing']->getBranchRegex())
  39. ->value('branch', null)
  40. ->convert('branch', 'escaper.argument:escape')
  41. ->bind('stats');
  42. $route->get('{repo}/{branch}/rss/', function($repo, $branch) use ($app) {
  43. $repository = $app['git']->getRepositoryFromName($app['git.repos'], $repo);
  44. if ($branch === null) {
  45. $branch = $repository->getHead();
  46. }
  47. $commits = $repository->getPaginatedCommits($branch);
  48. $html = $app['twig']->render('rss.twig', array(
  49. 'repo' => $repo,
  50. 'branch' => $branch,
  51. 'commits' => $commits,
  52. ));
  53. return new Response($html, 200, array('Content-Type' => 'application/rss+xml'));
  54. })->assert('repo', $app['util.routing']->getRepositoryRegex())
  55. ->assert('branch', $app['util.routing']->getBranchRegex())
  56. ->value('branch', null)
  57. ->convert('branch', 'escaper.argument:escape')
  58. ->bind('rss');
  59. return $route;
  60. }
  61. }