Skip to content

Commit

Permalink
Add twig to php compiler #2
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Aug 25, 2019
1 parent f6550dc commit 0c33d99
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
23 changes: 3 additions & 20 deletions bin/parse-twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// Translate the text and save the file.
//

use Odan\Twig\TwigCompiler;
use Slim\App;
use Twig\Environment as Twig;

Expand All @@ -29,23 +30,5 @@

$twig = $app->getContainer()->get(Twig::class);

$twig->disableDebug();

// Force auto-reload to always have the latest version of the template
$twig->enableAutoReload();

// The Twig cache must be enabled
$twig->setCache($cachePath);

// Iterate over all your templates
$directory = new RecursiveDirectoryIterator($templatePath, FilesystemIterator::SKIP_DOTS);

foreach (new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST) as $file) {
/** @var SplFileInfo $file */
if ($file->isFile() && $file->getExtension() === 'twig') {
$templateName = substr($file->getPathname(), strlen($templatePath) + 1);
$templateName = str_replace('\\', '/', $templateName);
echo sprintf("Parsing: %s\n", $templateName);
$twig->loadTemplate($templateName);
}
}
$compiler = new TwigCompiler($twig, $cachePath);
$compiler->compile();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"nyholm/psr7": "^1.2",
"nyholm/psr7-server": "^0.3.0",
"odan/twig-assets": "^2.1",
"odan/twig-translation": "^1.2",
"odan/twig-translation": "^1.2.1",
"psr/log": "^1.1",
"selective/basepath": "^0.1.0",
"slim/slim": "^4.1",
Expand Down

0 comments on commit 0c33d99

Please sign in to comment.