From 899dc431b835d957306f5b7327e673b23f5142e4 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sat, 9 Jul 2022 13:14:08 -0400 Subject: [PATCH] Initial Slim setup with Twig views --- app/bootstrap.php | 38 +++++++ app/routes.php | 10 ++ composer.json | 3 +- composer.lock | 269 +++++++++++++++++++++++++++++++++++++++++++++- phpcs.xml | 17 --- phpstan.neon.dist | 4 - phpunit.xml | 27 ----- public/index.php | 5 + views/index.twig | 1 + 9 files changed, 323 insertions(+), 51 deletions(-) create mode 100644 app/bootstrap.php create mode 100644 app/routes.php delete mode 100644 phpcs.xml delete mode 100644 phpstan.neon.dist delete mode 100644 phpunit.xml create mode 100644 public/index.php create mode 100644 views/index.twig diff --git a/app/bootstrap.php b/app/bootstrap.php new file mode 100644 index 0000000..c0fe6c0 --- /dev/null +++ b/app/bootstrap.php @@ -0,0 +1,38 @@ +addRoutingMiddleware(); + +/** + * Add Error Middleware + * + * @param bool $displayErrorDetails -> Should be set to false in production + * @param bool $logErrors -> Parameter is passed to the default ErrorHandler + * @param bool $logErrorDetails -> Display error details in error log + * @param LoggerInterface|null $logger -> Optional PSR-3 Logger + * + * Note: This middleware should be added last. It will not handle any exceptions/errors + * for middleware added after it. + */ +$errorMiddleware = $app->addErrorMiddleware(true, true, true); + +// Create Twig +$twig = Twig::create(__DIR__ . '/../views', ['cache' => false]); + +// Add Twig-View Middleware +$app->add(TwigMiddleware::create($app, $twig)); + +// Instantiate routes +require_once __DIR__ . '/routes.php'; diff --git a/app/routes.php b/app/routes.php new file mode 100644 index 0000000..ebe444a --- /dev/null +++ b/app/routes.php @@ -0,0 +1,10 @@ +get('/', function (Request $request, Response $response, array $args) { + $view = Twig::fromRequest($request); + return $view->render($response, 'index.twig'); +}); diff --git a/composer.json b/composer.json index 63530e1..2e01be7 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ ], "require": { "slim/slim": "^4.10", - "slim/twig-view": "^3.3" + "slim/twig-view": "^3.3", + "slim/psr7": "^1.5" } } diff --git a/composer.lock b/composer.lock index bfb1f2f..937c254 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,64 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c1ae4bb9354aab3cbd94934f19b77108", + "content-hash": "c3821ea78367ec91e146399d1869f6e9", "packages": [ + { + "name": "fig/http-message-util", + "version": "1.1.5", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message-util.git", + "reference": "9d94dc0154230ac39e5bf89398b324a86f63f765" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message-util/zipball/9d94dc0154230ac39e5bf89398b324a86f63f765", + "reference": "9d94dc0154230ac39e5bf89398b324a86f63f765", + "shasum": "" + }, + "require": { + "php": "^5.3 || ^7.0 || ^8.0" + }, + "suggest": { + "psr/http-message": "The package containing the PSR-7 interfaces" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Fig\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Utility classes and constants for use with PSR-7 (psr/http-message)", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "issues": "https://github.com/php-fig/http-message-util/issues", + "source": "https://github.com/php-fig/http-message-util/tree/1.1.5" + }, + "time": "2020-11-24T22:02:12+00:00" + }, { "name": "nikic/fast-route", "version": "v1.3.0", @@ -381,6 +437,132 @@ }, "time": "2021-05-03T11:20:27+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "slim/psr7", + "version": "1.5", + "source": { + "type": "git", + "url": "https://github.com/slimphp/Slim-Psr7.git", + "reference": "a47b43a8da7c0208b4c228af0cb29ea36080635a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slimphp/Slim-Psr7/zipball/a47b43a8da7c0208b4c228af0cb29ea36080635a", + "reference": "a47b43a8da7c0208b4c228af0cb29ea36080635a", + "shasum": "" + }, + "require": { + "fig/http-message-util": "^1.1.5", + "php": "^7.3 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0", + "symfony/polyfill-php80": "^1.23" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "adriansuter/php-autoload-override": "^1.2", + "ext-json": "*", + "http-interop/http-factory-tests": "^0.9.0", + "php-http/psr7-integration-tests": "dev-master", + "phpspec/prophecy": "^1.14", + "phpspec/prophecy-phpunit": "^2.0", + "phpstan/phpstan": "^0.12.99", + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "^3.6" + }, + "type": "library", + "autoload": { + "psr-4": { + "Slim\\Psr7\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Josh Lockhart", + "email": "hello@joshlockhart.com", + "homepage": "http://joshlockhart.com" + }, + { + "name": "Andrew Smith", + "email": "a.smith@silentworks.co.uk", + "homepage": "http://silentworks.co.uk" + }, + { + "name": "Rob Allen", + "email": "rob@akrabat.com", + "homepage": "http://akrabat.com" + }, + { + "name": "Pierre Berube", + "email": "pierre@lgse.com", + "homepage": "http://www.lgse.com" + } + ], + "description": "Strict PSR-7 implementation", + "homepage": "https://www.slimframework.com", + "keywords": [ + "http", + "psr-7", + "psr7" + ], + "support": { + "issues": "https://github.com/slimphp/Slim-Psr7/issues", + "source": "https://github.com/slimphp/Slim-Psr7/tree/1.5" + }, + "time": "2021-09-22T04:33:00+00:00" + }, { "name": "slim/slim", "version": "4.10.0", @@ -726,6 +908,89 @@ ], "time": "2022-05-24T11:49:31+00:00" }, + { + "name": "symfony/polyfill-php80", + "version": "v1.26.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/cfa0ae98841b9e461207c13ab093d76b0fa7bace", + "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.26-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php80/tree/v1.26.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-05-10T07:21:04+00:00" + }, { "name": "symfony/polyfill-php81", "version": "v1.26.0", @@ -890,5 +1155,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.2.0" } diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 72e9907..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - Slim coding standard - - - - - - - - - - - - src - tests - \ No newline at end of file diff --git a/phpstan.neon.dist b/phpstan.neon.dist deleted file mode 100644 index 2e09595..0000000 --- a/phpstan.neon.dist +++ /dev/null @@ -1,4 +0,0 @@ -parameters: - level: 4 - paths: - - src diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index f830400..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - ./tests/ - - - - - ./src/ - - - diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..b6b698f --- /dev/null +++ b/public/index.php @@ -0,0 +1,5 @@ +run(); diff --git a/views/index.twig b/views/index.twig new file mode 100644 index 0000000..959235b --- /dev/null +++ b/views/index.twig @@ -0,0 +1 @@ +

This is a test.

\ No newline at end of file