Skip to content
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

#674 Special interpretation of \DI\value in \DI\Container::set #675

Merged
merged 1 commit into from Jul 8, 2019

Conversation

downace
Copy link
Contributor

@downace downace commented Jul 4, 2019

This fixes #674

\DI\value now can be used in \DI\Container::set to set raw values. This is useful when you need to set a Closure as raw value because by default Closures are interpreted as factories:

$container->set('foo', function() { return 'bar' }));
$container->get('foo'); // returns 'bar'

$container->set('foo', \DI\value(function() { return 'bar' })));
$container->get('foo'); // returns Closure

`\DI\value` could be used in `\DI\Container::set` to set raw values.
This is useful when you need to set a `Closure` as raw value because by
default `Closure`s are interpreted as factories:

```
$container->set('foo', function() { return 'bar' }));
$container->get('foo'); // returns 'bar'

$container->set('foo', \DI\value(function() { return 'bar' })));
$container->get('foo'); // returns Closure
```
@mnapoli mnapoli added the bug label Jul 8, 2019
@mnapoli
Copy link
Member

mnapoli commented Jul 8, 2019

Thank you this is perfect!

@mnapoli mnapoli merged commit 00a5eb0 into PHP-DI:master Jul 8, 2019
@downace downace deleted the 674-container-set-value-definition branch July 8, 2019 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to set a closure as value to compiled container?
2 participants