*/ class Controller { protected $app; public function __construct(Application $app) { $this->app = $app; } public function getApp() { return $this->app; } protected function notFoundResponse() { $app = $this->getApp(); return new Response( $app['twig']->render( 'View/notFound.html.twig', [] ), 404 ); } protected function getViewOptions(Request $request, $gist, $commit) { $app = $this->getApp(); $gist = GistQuery::create()->findOneByFile($gist); if (null === $gist) { return null; } $history = $app['gist']->getHistory($gist); if (empty($history)) { return null; } $content = $this->getContentByCommit($gist, $commit, $history); return array( 'gist' => $gist, 'type' => $gist->getType(), 'history' => $history, 'commit' => $commit, 'raw_content' => $content, 'content' => $app['gist']->highlight($gist->getGeshiType(), $content), ); } protected function getContentByCommit(Gist $gist, &$commit, $history) { $app = $this->getApp(); if ($commit === 0) { $commit = $history[0]['commit']; } else { $commitExists = false; foreach ($history as $ci) { if ($commit === $ci['commit']) { $commitExists = true; } } if (!$commitExists) { return null; } } return $app['gist']->getContent($gist, $commit); } public function getUser() { $app = $this->getApp(); $securityContext = $app['security']; $securityToken = $securityContext->getToken(); if (!$securityToken) { return null; } return $securityToken->getUser(); } public function render($template, array $params) { $app = $this->getApp(); if (!isset($params['user'])) { $params['user'] = $this->getUser(); } return $app['twig']->render( $template, $params ); } }