-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Tweaked factories #12065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
562b870
to
4264436
Compare
@@ -618,8 +617,7 @@ private function addService($id, $definition) | |||
$this->addServiceMethodCalls($id, $definition). | |||
$this->addServiceProperties($id, $definition). | |||
$this->addServiceConfigurator($id, $definition). | |||
$this->addServiceReturn($id, $definition) | |||
; | |||
$this->addServiceReturn($id, $definition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that but PHP-CS-Fixer is buggy here. The previous code was "better". Can you revert this one and the other one as well. Thanks.
4264436
to
cf905b7
Compare
if ($definition->isSynthetic()) {
$return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
} elseif ($class = $definition->getClass()) {
$return[] = sprintf("@return %s A %s instance.", 0 === strpos($class, '%') ? 'object' : "\\".$class, $class);
} elseif ($definition->getFactory()) {
$factory = $definition->getFactory();
if (is_string($factory)) {
$return[] = sprintf('@return object An instance returned by %s().', $factory);
} elseif (is_array($factory) && (is_string($factory[0]) || $factory[0] instanceof Definition || $factory[0] instanceof Reference)) {
if (is_string($factory[0]) || $factory[0] instanceof Reference) {
$return[] = sprintf('@return object An instance returned by %s::%s().', (string) $factory[0], $factory[1]);
} elseif ($factory[0] instanceof Definition) {
$return[] = sprintf('@return object An instance returned by %s::%s().', $factory[0]->getClass(), $factory[1]);
}
}
} elseif ($definition->getFactoryClass()) {
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod());
} elseif ($definition->getFactoryService()) {
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryService(), $definition->getFactoryMethod());
} I thought it is not allowed to define service without |
I'll fix tests later. |
👍 once tests are fixed |
@@ -955,6 +955,18 @@ public function createService(Definition $definition, $id, $tryProxy = true) | |||
} | |||
|
|||
$service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments); | |||
} elseif (null !== $definition->getFactory()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the factory should win over the factory method, to be consistent with the code generated for dumped containers
Please also add a test instantiating a service with a factory in the ContainerBuilder (well, several to cover the different cases) |
b6ee1f8
to
d9f2720
Compare
Sorry for delay, tests have been updated. |
d9f2720
to
ee82392
Compare
Looks good to me @unkind. This is merged now. Thanks. |
This PR was merged into the 2.6-dev branch. Discussion ---------- [DependencyInjection] Tweaked factories | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12008 | License | MIT | Doc PR | n/a There are some issues with new service factories: * `ContainerBuilder` cannot instantiate service from factory (i.e. currently it works for dumped code only) * Dumped code sometimes is invalid (anonymous services as factories, factories without arguments) Commits ------- ee82392 [DependencyInjection] Tweaked factories
There are some issues with new service factories:
ContainerBuilder
cannot instantiate service from factory (i.e. currently it works for dumped code only)