-
-
Notifications
You must be signed in to change notification settings - Fork 324
Factories ignore default parameters #526
Copy link
Copy link
Closed
Description
When using a factorie for a parameter the default values are ignored. Instead the container or the definition is injected.
Example:
$builder = new \DI\ContainerBuilder();
$builder->addDefinitions([
'test' => \DI\factory('htmlentities')->parameter('string', '<something>'),
]);
$container = $builder->build();
echo $container->get('test');
This fails with the following exception:
DI\Definition\Exception\InvalidDefinition: Entry "test" cannot be resolved: Unable to invoke the callable because no value was given for parameter 3 ($encoding)
Parameter 2 is not mentioned because the container and the definition are injected as per this test:
class test {
public function dummy($a = null, $b = null) {
echo get_class($a) . PHP_EOL;
echo get_class($b);
}
}
$builder = new \DI\ContainerBuilder();
$builder->addDefinitions([
'factory_test' => \DI\factory(['test', 'dummy']),
]);
$container = $builder->build();
$test = $container->get('factory_test');
This produces:
DI\Container DI\Definition\FactoryDefinition
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels