-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TreeWalker): Added new tag `roadiz_core.tree_walker_definition_f…
…actory` to inject TreeWalker definitions into TreeWalkerGenerator and any BlocksAwareWebResponseOutputDataTransformerTrait
- Loading branch information
1 parent
ddc9ec7
commit 86e5ac6
Showing
7 changed files
with
173 additions
and
10 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
27 changes: 27 additions & 0 deletions
27
lib/RoadizCoreBundle/src/Api/TreeWalker/Definition/DefinitionFactoryConfiguration.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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Api\TreeWalker\Definition; | ||
|
||
final class DefinitionFactoryConfiguration | ||
{ | ||
/** | ||
* @var class-string | ||
*/ | ||
public string $classname; | ||
public bool $onlyVisible; | ||
public DefinitionFactoryInterface $definitionFactory; | ||
|
||
/** | ||
* @param class-string $classname | ||
* @param DefinitionFactoryInterface $definitionFactory | ||
* @param bool $onlyVisible | ||
*/ | ||
public function __construct(string $classname, DefinitionFactoryInterface $definitionFactory, bool $onlyVisible) | ||
{ | ||
$this->classname = $classname; | ||
$this->onlyVisible = $onlyVisible; | ||
$this->definitionFactory = $definitionFactory; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
lib/RoadizCoreBundle/src/Api/TreeWalker/Definition/DefinitionFactoryInterface.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Api\TreeWalker\Definition; | ||
|
||
use RZ\TreeWalker\WalkerContextInterface; | ||
|
||
interface DefinitionFactoryInterface | ||
{ | ||
public function create(WalkerContextInterface $context, bool $onlyVisible = true): callable; | ||
} |
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
43 changes: 43 additions & 0 deletions
43
...izCoreBundle/src/DependencyInjection/Compiler/TreeWalkerDefinitionFactoryCompilerPass.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,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\DependencyInjection\Compiler; | ||
|
||
use RZ\Roadiz\CoreBundle\Api\TreeWalker\TreeWalkerGenerator; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class TreeWalkerDefinitionFactoryCompilerPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
if ($container->has(TreeWalkerGenerator::class)) { | ||
$definition = $container->findDefinition(TreeWalkerGenerator::class); | ||
$serviceIds = $container->findTaggedServiceIds( | ||
'roadiz_core.tree_walker_definition_factory', | ||
); | ||
foreach ($serviceIds as $serviceId => $tags) { | ||
foreach ($tags as $tag) { | ||
if (isset($tag['classname']) && \is_string($tag['classname'])) { | ||
/* | ||
* TreeWalkerGenerator::addDefinitionFactoryConfiguration($classname, $serviceId, $onlyVisible = true) | ||
*/ | ||
$definition->addMethodCall( | ||
'addDefinitionFactoryConfiguration', | ||
[ | ||
$tag['classname'], | ||
new Reference($serviceId), | ||
$tag['onlyVisible'] ?? 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