Skip to content

Commit

Permalink
Add slim/twig-view
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Sep 1, 2019
1 parent 7ab45a7 commit b6338d8
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 14 deletions.
19 changes: 17 additions & 2 deletions bin/parse-twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"@check-style",
"@phpstan",
"@test-coverage"
]
],
"parse-twig": "php bin/parse-twig.php"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
$translator = new Translator(
$settings['locale'],
new MessageFormatter(new IdentityTranslator()),
$settings['cache']
$settings['cache'],
$settings['debug']
);

$translator->addLoader('mo', new MoFileLoader());
Expand Down
6 changes: 4 additions & 2 deletions config/defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
];

Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions config/development.php
Original file line number Diff line number Diff line change
@@ -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'] = '';
35 changes: 35 additions & 0 deletions config/env.example.php
Original file line number Diff line number Diff line change
@@ -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'] = '';
19 changes: 19 additions & 0 deletions config/integration.php
Original file line number Diff line number Diff line change
@@ -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'] = '';
7 changes: 7 additions & 0 deletions config/production.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Production environment
$settings['env'] = 'production';

// Database
$settings['db']['database'] = 'prod_dbname';
2 changes: 1 addition & 1 deletion config/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}

if (defined('APP_ENV')) {
//require __DIR__ . '/' . APP_ENV . '.php';
require __DIR__ . '/' . basename(APP_ENV) . '.php';
}

return $settings;
Expand Down
7 changes: 7 additions & 0 deletions config/staging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Staging environment
$settings['env'] = 'staging';

// Database
$settings['db']['database'] = 'staging_dbname';
11 changes: 11 additions & 0 deletions config/testing.php
Original file line number Diff line number Diff line change
@@ -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';
Binary file modified resources/locale/de_DE_messages.mo
Binary file not shown.
13 changes: 7 additions & 6 deletions resources/locale/de_DE_messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -114,9 +118,6 @@ msgstr "Aktuelle Zeit"
#~ msgid "Toggle navigation"
#~ msgstr "Navigation umschalten"

#~ msgid "Home"
#~ msgstr "Home"

#~ msgid "Link"
#~ msgstr "Link"

Expand Down
2 changes: 1 addition & 1 deletion templates/Time/time-index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/HttpTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
Expand Down

0 comments on commit b6338d8

Please sign in to comment.