Reputation: 166106
Short Version: What populates the sylius.resource_registry
service with data?
Long Version: Sylius, (a PHP ecommerce framework built using Symfony) uses Symfony's custom route loading system to load some additional routes based on special configuration values. The custom route loader class name is Sylius\Bundle\ResourceBundle\Routing\ResourceLoader
.
There's logic in this resource loader that looks for an alias (example value of an alias), and then uses that alias to load metadata from a registry.
$metadata = $this->resourceRegistry->get($configuration['alias']);
This registry is a symfony service with the identifier sylius.resource_registry
, configured here.
#File: vendor/sylius/sylius/src/Sylius/Bundle/ResourceBundle/Resources/config/services.xml
<service id="sylius.resource_registry" class="Sylius\Component\Resource\Metadata\Registry" public="false" />
and injected here.
#File: vendor/sylius/sylius/src/Sylius/Bundle/ResourceBundle/Resources/config/services/routing.xml
<service id="sylius.routing.loader.resource" class="Sylius\Bundle\ResourceBundle\Routing\ResourceLoader" public="false">
<argument type="service" id="sylius.resource_registry" />
<argument type="service">
<service class="Sylius\Bundle\ResourceBundle\Routing\RouteFactory" />
</argument>
<tag name="routing.loader" />
</service>
However, the Sylius\Component\Resource\Metadata\Registry
class has no constructor, so it's not clear what populates the private $metadata array. There are methods named add
and addFromAliasAndConfiguration
which ~mutate the state~ adds values to the $metadata
array, but it's not clear what code calls these methods, and/or what sylius configuration causes those methods to be called.
After chasing this down as far as I have, I'm not sure how deep this rabbit hole goes, so I turn to you Stack Overflow: What populates the sylius.resource_registry
service with data?
Upvotes: 1
Views: 644
Reputation: 2310
A Symfony compiler pass does it. Specifially: https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/ResourceBundle/DependencyInjection/Compiler/RegisterResourcesPass.php
It loads the configuration from sylius.resources
Symfony container parameter and it adds a method call to addFromAliasAndConfiguration
to service definition of sylius.resource_registry
for every resource it finds in sylius.resources
.
Upvotes: 3