-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TwigHooks] Implement autoprefixing feature (#4)
This PR introduces the autoprefixing feature. Previously we were forced to pass the whole hook name while declaring it. From now, we can a) pass a magic `_prefixes` variable along with the **hook context (!)** ```twig {% hook 'base' with { _prefixes: ['app', 'sylius_twig_hooks'] } %} ``` b) automatically resolve the `prefixes` passed with the `HookableMetadata` and prefix the short hook name. ```twig {# considering there are `app.index, twig_hooks.index` prefixes in the metadata object #} {% hook 'content' %} {# will produce app.index.content and twig_hooks.index.content keeping the order of prefixes #} ``` This feature will be documented more detailed later.
- Loading branch information
Showing
53 changed files
with
490 additions
and
169 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
when@dev: | ||
debug: | ||
# Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser. | ||
# See the "server:dump" command to start a new server. | ||
dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%" |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
twig: | ||
default_path: '%kernel.project_dir%/templates' | ||
|
||
twig_component: | ||
anonymous_template_directory: 'components/' | ||
|
||
when@test: | ||
twig: | ||
strict_variables: true |
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,5 @@ | ||
twig_hooks: | ||
hooks: | ||
'app.base': | ||
content: | ||
template: 'base/content.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
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,6 @@ | ||
parameters: | ||
ignoreErrors: | ||
- | ||
message: "#^Unsafe usage of new static\\(\\)\\.$#" | ||
count: 1 | ||
path: src/TwigHooks/src/Hookable/AbstractHookable.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
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
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\TwigHooks\Hook\Metadata; | ||
|
||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
|
||
class HookMetadata | ||
{ | ||
public function __construct( | ||
public readonly string $name, | ||
public readonly ParameterBagInterface $context, | ||
) { | ||
} | ||
} |
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
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\TwigHooks\Hookable\Metadata; | ||
|
||
use Sylius\TwigHooks\Hook\Metadata\HookMetadata; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
|
||
class HookableMetadata | ||
{ | ||
/** | ||
* @param array<string> $prefixes | ||
*/ | ||
public function __construct( | ||
public readonly HookMetadata $renderedBy, | ||
public readonly ParameterBagInterface $context, | ||
public readonly ParameterBagInterface $configuration, | ||
public readonly array $prefixes = [], | ||
) { | ||
foreach ($prefixes as $prefix) { | ||
if (!is_string($prefix)) { | ||
throw new \InvalidArgumentException('Parent name must be a string.'); | ||
} | ||
} | ||
} | ||
|
||
public function hasPrefixes(): bool | ||
{ | ||
return count($this->prefixes) > 0; | ||
} | ||
} |
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
Oops, something went wrong.