diff --git a/bin/parse-twig.php b/bin/parse-twig.php index 495a87857..3d53f0777 100644 --- a/bin/parse-twig.php +++ b/bin/parse-twig.php @@ -19,7 +19,12 @@ use Odan\Twig\TwigCompiler; use Slim\App; -use Twig\Environment as Twig; +use Slim\Psr7\Factory\ServerRequestFactory; +use Slim\Views\Twig; +use Slim\Views\TwigExtension; +use Slim\Views\TwigRuntimeLoader; + +define('APP_ENV', 'integration'); /** @var App $app */ $app = require __DIR__ . '/../config/bootstrap.php'; @@ -28,9 +33,19 @@ $templatePath = (string)$settings['path']; $cachePath = (string)$settings['cache_path']; -$twig = $app->getContainer()->get(Twig::class); +$twig = $app->getContainer()->get(Twig::class)->getEnvironment(); + +$routeParser = $app->getRouteCollector()->getRouteParser(); +$basePath = $app->getBasePath(); +$factory = new ServerRequestFactory(); +$request = $factory->createServerRequest('GET', '/'); +$runtimeLoader = new TwigRuntimeLoader($routeParser, $request->getUri(), $basePath); +$twig->addRuntimeLoader($runtimeLoader); +$twig->addExtension(new TwigExtension()); $compiler = new TwigCompiler($twig, $cachePath, true); $compiler->compile(); echo "Done\n"; + +return 0; diff --git a/composer.json b/composer.json index ae726b131..54ea1a4e7 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ "@check-style", "@phpstan", "@test-coverage" - ] + ], + "parse-twig": "php bin/parse-twig.php" }, "autoload": { "psr-4": { diff --git a/config/container.php b/config/container.php index 4802f6ddb..a195a4e16 100644 --- a/config/container.php +++ b/config/container.php @@ -111,7 +111,8 @@ $translator = new Translator( $settings['locale'], new MessageFormatter(new IdentityTranslator()), - $settings['cache'] + $settings['cache'], + $settings['debug'] ); $translator->addLoader('mo', new MoFileLoader()); diff --git a/config/defaults.php b/config/defaults.php index 3c9f95bb2..93463f88f 100644 --- a/config/defaults.php +++ b/config/defaults.php @@ -23,7 +23,7 @@ 'display_error_details' => true, // Parameter is passed to the default ErrorHandler // View in rendered output by enabling the "displayErrorDetails" setting. - // For the console and unit tests we also disable + // For the console and unit tests we also disable it 'log_errors' => true, // Display error details in error log 'log_error_details' => true, @@ -47,7 +47,7 @@ $settings['twig'] = [ 'path' => $settings['root'] . '/templates', // Should be set to true in production - 'cache_enabled' => false, + 'cache_enabled' => true, 'cache_path' => $settings['temp'] . '/twig-cache', ]; @@ -76,6 +76,8 @@ 'cache' => $settings['temp'] . '/locale-cache', 'locale' => 'en_US', 'domain' => 'messages', + // Should be set to false in production + 'debug' => false, ]; // Phinx settings diff --git a/config/development.php b/config/development.php new file mode 100644 index 000000000..b2f9b029c --- /dev/null +++ b/config/development.php @@ -0,0 +1,17 @@ +<?php + +error_reporting(E_ALL); +ini_set('display_errors', '1'); + +$settings['env'] = 'development'; + +$settings['error_handler_middleware']['log_errors'] = false; +$settings['logger']['level'] = \Monolog\Logger::DEBUG; +$settings['assets']['minify'] = 0; +$settings['locale']['cache'] = null; +$settings['twig']['cache_enabled'] = false; + +// Database +$settings['db']['database'] = 'test'; +$settings['db']['username'] = 'root'; +$settings['db']['password'] = ''; diff --git a/config/env.example.php b/config/env.example.php new file mode 100644 index 000000000..4c15bf0d3 --- /dev/null +++ b/config/env.example.php @@ -0,0 +1,35 @@ +<?php + +/** + * Environment specific application configuration. + * + * You should store all secret information (username, password, token) here. + * + * Make sure the env.php file is added to your .gitignore + * so it is not checked-in the code + * + * Place the env.php _outside_ the project root directory, to protect against + * overwriting at deployment. + * + * This usage ensures that no sensitive passwords or API keys will + * ever be in the version control history so there is less risk of + * a security breach, and production values will never have to be + * shared with all project collaborators. + */ +require __DIR__ . '/development.php'; + +error_reporting(E_ALL); +ini_set('display_errors', '1'); + +$settings['env'] = 'development'; + +$settings['error_handler_middleware']['log_errors'] = false; +$settings['logger']['level'] = \Monolog\Logger::DEBUG; +$settings['assets']['minify'] = 0; +$settings['locale']['cache'] = null; +$settings['twig']['cache_enabled'] = false; + +// Database +$settings['db']['database'] = 'test'; +$settings['db']['username'] = 'root'; +$settings['db']['password'] = ''; diff --git a/config/integration.php b/config/integration.php new file mode 100644 index 000000000..e6bd35ea3 --- /dev/null +++ b/config/integration.php @@ -0,0 +1,19 @@ +<?php + +// Error reporting +error_reporting(E_ALL); +ini_set('display_errors', '1'); + +// Continuous integration environment +$settings['env'] = 'integration'; + +$settings['error_handler_middleware']['log_errors'] = false; +$settings['logger']['level'] = \Monolog\Logger::DEBUG; +$settings['assets']['minify'] = 0; +$settings['locale']['cache'] = null; +$settings['twig']['cache_enabled'] = false; + +// Database +$settings['db']['database'] = 'test'; +$settings['db']['username'] = 'root'; +$settings['db']['password'] = ''; diff --git a/config/production.php b/config/production.php new file mode 100644 index 000000000..6e1fb19a9 --- /dev/null +++ b/config/production.php @@ -0,0 +1,7 @@ +<?php + +// Production environment +$settings['env'] = 'production'; + +// Database +$settings['db']['database'] = 'prod_dbname'; diff --git a/config/settings.php b/config/settings.php index 0d51bac4f..196ceeafd 100644 --- a/config/settings.php +++ b/config/settings.php @@ -12,7 +12,7 @@ } if (defined('APP_ENV')) { - //require __DIR__ . '/' . APP_ENV . '.php'; + require __DIR__ . '/' . basename(APP_ENV) . '.php'; } return $settings; diff --git a/config/staging.php b/config/staging.php new file mode 100644 index 000000000..ea9be1c59 --- /dev/null +++ b/config/staging.php @@ -0,0 +1,7 @@ +<?php + +// Staging environment +$settings['env'] = 'staging'; + +// Database +$settings['db']['database'] = 'staging_dbname'; diff --git a/config/testing.php b/config/testing.php new file mode 100644 index 000000000..69bb58642 --- /dev/null +++ b/config/testing.php @@ -0,0 +1,11 @@ +<?php + +// Testing environment +$settings['env'] = 'testing'; + +// Error reporting +error_reporting(E_ALL); +ini_set('display_errors', '1'); + +// Database +$settings['db']['database'] = 'test_dbname'; diff --git a/resources/locale/de_DE_messages.mo b/resources/locale/de_DE_messages.mo index c2a40f888..b20dc1faa 100644 Binary files a/resources/locale/de_DE_messages.mo and b/resources/locale/de_DE_messages.mo differ diff --git a/resources/locale/de_DE_messages.po b/resources/locale/de_DE_messages.po index 5e2f0031e..8d94408fa 100644 --- a/resources/locale/de_DE_messages.po +++ b/resources/locale/de_DE_messages.po @@ -2,8 +2,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-08-25 22:16+0200\n" -"PO-Revision-Date: 2019-08-25 22:16+0200\n" +"POT-Creation-Date: 2019-09-01 16:43+0200\n" +"PO-Revision-Date: 2019-09-01 16:47+0200\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" @@ -17,10 +17,14 @@ msgstr "" "X-Poedit-SearchPath-0: src\n" "X-Poedit-SearchPath-1: tmp/twig-cache\n" -#: tmp/twig-cache/b0/b08ae06e89f7c1e908c0731b35e84c0b3e3279a56c5d89492838e25dc98c7353.php:72 +#: tmp/twig-cache/00/00a0ad589fa3a20936eccc84a3a70ec46ff1d039513fce17afa698fc0e3bb9f3.php:72 msgid "Current time" msgstr "Aktuelle Zeit" +#: tmp/twig-cache/00/00a0ad589fa3a20936eccc84a3a70ec46ff1d039513fce17afa698fc0e3bb9f3.php:83 +msgid "Home" +msgstr "Startseite" + #~ msgid "User list" #~ msgstr "Benutzerliste" @@ -114,9 +118,6 @@ msgstr "Aktuelle Zeit" #~ msgid "Toggle navigation" #~ msgstr "Navigation umschalten" -#~ msgid "Home" -#~ msgstr "Home" - #~ msgid "Link" #~ msgstr "Link" diff --git a/templates/Time/time-index.twig b/templates/Time/time-index.twig index a748eef16..e3e5efb68 100644 --- a/templates/Time/time-index.twig +++ b/templates/Time/time-index.twig @@ -14,7 +14,7 @@ </div> <div class="col-md-12"> - <a href="{{ url_for('root') }}">Home</a> + <a href="{{ url_for('root') }}">{{ __('Home') }}</a> </div> </div> </div> diff --git a/tests/TestCase/HttpTestTrait.php b/tests/TestCase/HttpTestTrait.php index fdc01f361..494b13f62 100644 --- a/tests/TestCase/HttpTestTrait.php +++ b/tests/TestCase/HttpTestTrait.php @@ -41,6 +41,7 @@ protected function createRequest(string $method, $uri, array $serverParams = []) // A phpunit fix #3026 if (!isset($_SERVER['REQUEST_URI'])) { $_SERVER = [ + 'SCRIPT_NAME' => '/public/index.php', 'REQUEST_TIME_FLOAT' => microtime(true), 'REQUEST_TIME' => microtime(), ];