Skip to content

Commit

Permalink
chore: update examples to include how symfony templating renders inco…
Browse files Browse the repository at this point in the history
…rrectly

Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz committed Dec 13, 2021
1 parent 07020d4 commit a036d43
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 11 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"require": {
"php": "~8.1",
"azjezz/psl": "^1.9.3 || ^2.0.0",
"azjezz/psl": "^2.0.0",
"ext-ctype": "*",
"ext-iconv": "*"
},
Expand All @@ -33,7 +33,8 @@
"vimeo/psalm": "^4.11.2",
"php-standard-library/psalm-plugin": "^1.1.1",
"php-coveralls/php-coveralls": "^2.5",
"roave/infection-static-analysis-plugin": "1.13.x-dev"
"roave/infection-static-analysis-plugin": "1.13.x-dev",
"symfony/templating": "6.1.x-dev"
},
"suggest": {
"psr/log-implementation": "For using debug logging in loaders"
Expand Down
76 changes: 73 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 42 additions & 6 deletions example/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
use Hype\Loader\FilesystemLoader;
use Hype\PHPEngine;
use Hype\TemplateNameParser;
use Psl\IO;
use Psl\Async;
use Psl\IO;

require __DIR__ . '/../vendor/autoload.php';

Async\main(static function (): void {
function hype(): void
{
$parser = new TemplateNameParser();
$loader = new FilesystemLoader([
__DIR__ . '/templates/%name%',
Expand All @@ -21,7 +22,7 @@

$time = microtime(true);

[$index, $contact] = Async\parallel([
[$index] = Async\parallel([
static fn() => $engine->render('index.php'),
static fn() => $engine->render('index.php'),
static fn() => $engine->render('contact.php'),
Expand All @@ -30,9 +31,44 @@

$duration = microtime(true) - $time;

IO\write_line('Rendered "%s", and "%s" twice, in %f second(s).', 'index.php', 'contact.php', $duration);
IO\write_line('Hype: rendered "%s", and "%s" twice, in %f second(s).', 'index.php', 'contact.php', $duration);
IO\write_line('');

IO\write_error_line($index);
IO\write_error_line($contact);
IO\write_line($index);
}

function symfony_templating(): void
{
$parser = new \Symfony\Component\Templating\TemplateNameParser();
$loader = new \Symfony\Component\Templating\Loader\FilesystemLoader([
__DIR__ . '/templates/%name%',
]);

$engine = new \Symfony\Component\Templating\PhpEngine($parser, $loader, [
new \Symfony\Component\Templating\Helper\SlotsHelper()
]);

$time = microtime(true);

[$index] = Async\parallel([
static fn() => $engine->render('index.php'),
static fn() => $engine->render('index.php'),
static fn() => $engine->render('contact.php'),
static fn() => $engine->render('contact.php'),
]);

$duration = microtime(true) - $time;

IO\write_line('Symfony: rendered "%s", and "%s" twice, in %f second(s).', 'index.php', 'contact.php', $duration);
IO\write_line('');

IO\write_line($index);
}

Async\main(static function(): int {
hype();

symfony_templating();

return 0;
});

0 comments on commit a036d43

Please sign in to comment.