[Feature Request] [Config] Simplify service extending services with other services
@butschster is already working on this.
Since Nov 11, 2022.
- Dominant language
- PHP
- Stars
- 2.1k
- Forks
- 92
- Avg merge
- 14h 57m
- Merged PRs (30d)
- 4
Description
Description
I'm very new to Spiral and looking how I can make my Spiral Modules extendable. I had a look at the following Config code in the Twig Bridge here:
At the wire part here:
This is something which maybe could be easier as extending a package with something from outside via own is a code is common pattern, which even some design patterns are build on top of it:
In Symfony service tags can be used to mark services with a tag which will then automatically be injected.
In Spiral maybe if service tags are not a way to go, I understand that, but maybe the exist code maybe could be moved into a HelperTrait or Helper Function. So that kind of mechanism of that lines could be more simplified and is provided by the Framework and not all need to copy it to there modules.
Example
Could the TwigConfig could look like this:
final class TwigConfig extends InjectableConfig
{
public const CONFIG = 'views/twig';
protected array $config = [
'options' => [],
'extensions' => [],
'processors' => [],
];
public function getOptions(): array
{
return $this->config['options'];
}
/**
* @return Autowire[]
*/
public function getExtensions(): array
{
return ServiceHelper::loadServices($this->config['extensions']);
}
/**
* @return Autowire[]
*/
public function getProcessors(): array
{
return ServiceHelper::loadServices($this->config['processors']);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.