diff --git a/src/helpers/GithubImporter.php b/src/helpers/GithubImporter.php index 6c3cf49..a655bef 100755 --- a/src/helpers/GithubImporter.php +++ b/src/helpers/GithubImporter.php @@ -9,6 +9,7 @@ namespace helpers; use Cache\Adapter\Filesystem\FilesystemCachePool; +use Github\AuthMethod; use Github\Client; use Github\ResultPager; use League\Flysystem\Adapter\Local; @@ -57,7 +58,7 @@ class GithubImporter { $client->addCache($pool); if (!empty($clientId)) { - $client->authenticate($clientId, null, Client::AUTH_HTTP_TOKEN); + $client->authenticate($clientId, null, AuthMethod::ACCESS_TOKEN); } return $client; diff --git a/src/helpers/Issue.php b/src/helpers/Issue.php index d164d78..ca4e143 100755 --- a/src/helpers/Issue.php +++ b/src/helpers/Issue.php @@ -15,7 +15,7 @@ class Issue { * Upfront you should check whether the issue actually exists by calling exists(). * * @param int $issueNumber - * @return bool + * @return array */ public function getIssue($issueNumber) { diff --git a/src/helpers/Page.php b/src/helpers/Page.php index 5f4a352..9d1c019 100755 --- a/src/helpers/Page.php +++ b/src/helpers/Page.php @@ -16,7 +16,7 @@ class Page * Upfront you should check whether the page actually exists by calling exists(). * * @param int $pageNumber - * @return bool + * @return array */ public function getPage($pageNumber) { $path = $this->getPathToFile($pageNumber); diff --git a/src/helpers/Twig.php b/src/helpers/Twig.php index 0fb9d5e..f119965 100755 --- a/src/helpers/Twig.php +++ b/src/helpers/Twig.php @@ -11,25 +11,25 @@ namespace helpers; class Twig { - public static function setDateFormat(\Twig_Environment $environment) { - $environment->getExtension("Twig_Extension_Core")->setDateFormat('F jS Y'); + public static function setDateFormat(\Twig\Environment $environment) { + $environment->getExtension("Twig\Extension\CoreExtension")->setDateFormat('F jS Y'); } - public static function registerFilter(\Twig_Environment $environment) { + public static function registerFilter(\Twig\Environment $environment) { $environment->addFilter(static::getMarkdownFilter()); $environment->addFilter(static::getColorFilter()); $environment->addFunction(static::getPaginationFunction()); } private static function getMarkdownFilter() { - return new \Twig_SimpleFilter('markdown', function ($text) { + return new \Twig\TwigFilter('markdown', function ($text) { $parser = new Markdown(); return $parser->text($text); }); } private static function getColorFilter() { - return new \Twig_SimpleFilter( + return new \Twig\TwigFilter( /** * modified from https://24ways.org/2010/calculating-color-contrast/ * @param $colorstring "#ffffff" @@ -45,7 +45,7 @@ class Twig } private static function getPaginationFunction() { - return new \Twig_Function('paginationFunction', function ($numPages, $page) { + return new \Twig\TwigFunction('paginationFunction', function ($numPages, $page) { $padding = PAGINATION_PADDING; $pages = [1]; $i = 2; diff --git a/src/public/index.php b/src/public/index.php index d9498cf..fae4167 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -10,28 +10,19 @@ require '../vendor/autoload.php'; require '../config/config.php'; date_default_timezone_set('UTC'); -$config = [ - 'settings' => [ - 'displayErrorDetails' => DEBUG_ENABLED, - ], -]; -$app = new \Slim\App($config); - -// Get container -$container = $app->getContainer(); +$container = new \DI\Container(); +\Slim\Factory\AppFactory::setContainer($container); // Register component on container -$container['view'] = function ($container) { - $view = new \Slim\Views\Twig(realpath("../templates/"), [ +$container->set('view', function () { + $view = \Slim\Views\Twig::create(realpath("../templates/"), [ 'cache' => realpath('../tmp/templates_cache'), 'debug' => DEBUG_ENABLED, ]); // Instantiate and add Slim specific extension - $basePath = rtrim(str_ireplace('index.php', '', $container['request']->getUri()->getBasePath()), '/'); - $view->addExtension(new Slim\Views\TwigExtension($container['router'], $basePath)); - $view->addExtension(new \Twig_Extension_Debug()); + $view->addExtension(new \Twig\Extension\DebugExtension()); $twig = $view->getEnvironment(); helpers\Twig::setDateFormat($twig); helpers\Twig::registerFilter($twig); @@ -44,7 +35,15 @@ $container['view'] = function ($container) { $view->getEnvironment()->addGlobal('privacyPolicyURL', PRIVACY_POLICY_URL); return $view; -}; +}); + +// Create App +$app = \Slim\Factory\AppFactory::create(); + +// Add Twig-View Middleware +$app->add(\Slim\Views\TwigMiddleware::createFromContainer($app)); + +$app->addErrorMiddleware(DEBUG_ENABLED, true, true); require '../routes/page.php'; diff --git a/src/routes/page.php b/src/routes/page.php index 1b136fb..8f1a69d 100644 --- a/src/routes/page.php +++ b/src/routes/page.php @@ -6,7 +6,6 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ - $app->get( '/{number:[0-9]+}', function ($request, $response, $args) { @@ -15,24 +14,26 @@ $app->get( $issue = new helpers\Issue(); if (!$issue->exists($number)) { - throw new \Slim\Exception\NotFoundException($request, $response); + throw new \Slim\Exception\HttpNotFoundException($request, $response); } $details = $issue->getIssue($number); - return $this->view->render($response, 'issue.twig', $details); + + return $this->get('view')->render($response, 'issue.twig', $details); })->setName("issue"); $app->get('/', function ($request, $response, $args) { - /** @var \Slim\Http\Request $request */ - $pageNumber = (int)$request->getQueryParam('page', 1); + /** @var \GuzzleHttp\Psr7\ServerRequest $request */ + $params = $request->getQueryParams(); + $pageNumber = $params['page'] ?? 1; $page = new helpers\Page(); if (!$page->exists($pageNumber)) { - throw new \Slim\Exception\NotFoundException($request, $response); + throw new \Slim\Exception\HttpNotFoundException($request, $response); } $details = $page->getPage($pageNumber); - return $this->view->render($response, 'page.twig', $details); -})->setName("page"); \ No newline at end of file + return $this->get('view')->render($response, 'page.twig', $details); +})->setName("page"); diff --git a/src/templates/macros.twig b/src/templates/macros.twig index e634ad4..5f44d32 100755 --- a/src/templates/macros.twig +++ b/src/templates/macros.twig @@ -21,7 +21,7 @@