-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f361f9b
commit 97bd55b
Showing
14 changed files
with
161 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/TwigHooks/src/Hook/Renderer/Debug/HookProfilerRenderer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\TwigHooks\Hook\Renderer\Debug; | ||
|
||
use Sylius\TwigHooks\Hook\Renderer\HookRendererInterface; | ||
use Sylius\TwigHooks\Profiler\Profile; | ||
use Symfony\Component\Stopwatch\Stopwatch; | ||
|
||
final class HookProfilerRenderer implements HookRendererInterface | ||
{ | ||
public function __construct ( | ||
private HookRendererInterface $innerRenderer, | ||
private ?Profile $profile, | ||
private ?Stopwatch $stopwatch, | ||
) { | ||
} | ||
|
||
public function render(array $hooksNames, array $data = []): string | ||
{ | ||
$this->profile?->registerHookStart($hooksNames); | ||
$this->stopwatch?->start(md5(serialize($hooksNames))); | ||
|
||
$rendered = $this->innerRenderer->render($hooksNames, $data); | ||
|
||
$this->profile?->registerHookEnd( | ||
$this->stopwatch?->stop(md5(serialize($hooksNames)))->getDuration(), | ||
); | ||
|
||
return $rendered; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/TwigHooks/src/Hookable/Renderer/Debug/HookableProfilerRenderer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\TwigHooks\Hookable\Renderer\Debug; | ||
|
||
use Sylius\TwigHooks\Hookable\AbstractHookable; | ||
use Sylius\TwigHooks\Hookable\Renderer\HookableRendererInterface; | ||
use Sylius\TwigHooks\Profiler\Profile; | ||
use Symfony\Component\Stopwatch\Stopwatch; | ||
|
||
final class HookableProfilerRenderer implements HookableRendererInterface | ||
{ | ||
public function __construct ( | ||
private readonly HookableRendererInterface $innerRenderer, | ||
private readonly ?Profile $profile, | ||
private readonly ?Stopwatch $stopwatch, | ||
) { | ||
} | ||
|
||
public function render(AbstractHookable $hookable, array $hookData = []): string | ||
{ | ||
$this->profile?->registerHookableRenderStart($hookable); | ||
$this->stopwatch?->start($hookable->getId()); | ||
|
||
$rendered = $this->innerRenderer->render($hookable, $hookData); | ||
|
||
$this->profile?->registerHookableRenderEnd( | ||
$this->stopwatch?->stop($hookable->getId())->getDuration(), | ||
); | ||
|
||
return $rendered; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...sts/Functional/.application/templates/parsing_hook_tag_test/multiple_hook_names.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% hook ['some_hook', 'another_hook'] %} |
1 change: 1 addition & 0 deletions
1
.../tests/Functional/.application/templates/parsing_hook_tag_test/single_hook_name.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% hook 'some_hook' %} |
46 changes: 46 additions & 0 deletions
46
src/TwigHooks/tests/Functional/Twig/ParsingHookTagTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\TwigHooks\Functional\Twig; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Twig\Environment as Twig; | ||
|
||
/** | ||
* @group kernel-required | ||
*/ | ||
final class ParsingHookTagTest extends KernelTestCase | ||
{ | ||
public function testItRendersSingleHookName(): void | ||
{ | ||
$this->assertSame( | ||
<<<EXPECTED | ||
<!-- BEGIN HOOK | name: "some_hook" --> | ||
<!-- END HOOK | name: "some_hook" --> | ||
EXPECTED, | ||
$this->render('parsing_hook_tag_test/single_hook_name.html.twig'), | ||
); | ||
} | ||
|
||
public function testItRendersMultipleHookNames(): void | ||
{ | ||
$this->assertSame( | ||
<<<EXPECTED | ||
<!-- BEGIN HOOK | name: "some_hook, another_hook" --> | ||
<!-- END HOOK | name: "some_hook, another_hook" --> | ||
EXPECTED, | ||
$this->render('parsing_hook_tag_test/multiple_hook_names.html.twig'), | ||
); | ||
} | ||
|
||
private function render(string $path): string | ||
{ | ||
/** @var Twig $twig */ | ||
$twig = $this->getContainer()->get('twig'); | ||
|
||
return $twig->render($path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters