DependencyInjection Component
The DependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.
Category: PHP / Dependency Injection |
Watchers: 16 |
Star: 3.8k |
Fork: 82 |
Last update: Jul 26, 2022 |
The DependencyInjection component allows you to standardize and centralize the way objects are constructed in your application.
Symfony\Component\DependencyInjection\Dumper\XmlDumper didn't write 'factory-class' XML attribute for definitions on which setFactoryClass() was set.
This caused the Container[Builder] to throw an exception when the relevant service is being requested/initiated after loading the dumped XML:
Uncaught Exception Symfony\Component\DependencyInjection\Exception\RuntimeException: "Cannot create service "xxx" from factory method without a factory service or factory class." at /<path>/<to>/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php
Fixed the problem, and updated relevant test fixture.
For example:
parameters: social: facebook: app_id: 1234567890
Now it's possible to get app_id like: $this->get('social:facebook:app_id');
The colon symbol ":" don't allowed for use in parameter name and it's the most appropriate symbol for separator. At last we get more conveniently for get nested arrays value.
I've got an error when I tried to use DI to initiate Monolog logger with next settings:
services:
logger_formatter:
class: \Monolog\Formatter\LineFormatter
arguments: [ "[%%datetime%%] %%channel%%.%%level_name%%: %%message%% %%context%%\n" ]
logger_handler:
class: \Monolog\Handler\StreamHandler
arguments:
- app.log
- <?php echo \Monolog\Logger::DEBUG, PHP_EOL; ?>
calls:
- [ setFormatter, [ @logger_formatter ]]
logger:
class: \Monolog\Logger
arguments: [ 'logger_name' ]
calls:
- [ pushHandler, [ @logger_handler ]]
If I set argument for service logger_formatter with single % (like "[%datetime%]…") then DI threw exception that it could not resolve reference because there was non-existent parameter "datetime". If I set argument with double % (like "[%%datetime%%]…") then DI transferred parameter to the LineFormatter object without unescaping, and LineFormatter did not work properly. The problem was in ContainerBuilder, because there was no unescaping class parameters.
I’ve fixed problem and added tests to cover such case.
When you have to much env variables and many services in your container, container compilаtion can take much time due to the function stripos which is called much time. Look at the bottom of picture https://i2.piccy.info/i9/cdc413af9aecce8f7ed5ca0fe69b6c7c/1640950765/149173/1453384/6833Screenshot_from_2021_12_31_13_38_20.png
It happens because function resolveEnvPlaceholders try to find env placeholders in any value, even when there is no possible env in string.
So i offer to check value on strings env_ or env( and if they are present than look for placeholders.
In my project it helps me to save 10 seconds in container building.
Q | A -- | -- Branch? | 6.0 Bug fix? | no New feature? | no Deprecations? | no License | MIT
Just extended two attributes that do not break compatibility, are optional and null. The feature only allows you to do almost the same as in YAML files, the configuration specifying defaultIndexMethod for:
ParameterBagInterface has comment on get method: @throws ParameterNotFoundException if the parameter is not defined but InvalidArgumentException is thrown.
Changelog (https://github.com/symfony/dependency-injection/compare/v6.1.2...v6.1.3)
Changelog (https://github.com/symfony/dependency-injection/compare/v6.0.10...v6.0.11)
Changelog (https://github.com/symfony/dependency-injection/compare/v5.4.10...v5.4.11)
Changelog (https://github.com/symfony/dependency-injection/compare/v4.4.43...v4.4.44)
Changelog (https://github.com/symfony/dependency-injection/compare/v6.1.1...v6.1.2)
Changelog (https://github.com/symfony/dependency-injection/compare/v6.0.9...v6.0.10)