Fixes #9331: betted PHP Callable Injection example

This commit is contained in:
Alexander Makarov
2015-09-05 01:53:20 +03:00
parent 6b2748a0b3
commit 112fc83f27

View File

@ -95,29 +95,25 @@ $container->set('Foo', function () {
$foo = $container->get('Foo');
```
To hide the complex logic for building a new object, you may use a static class method to return the PHP
callable. For example,
To hide the complex logic for building a new object, you may use a static class method as callable. For example,
```php
class FooBuilder
{
public static function build()
{
return function () {
$foo = new Foo(new Bar);
// ... other initializations ...
return $foo;
};
}
}
$container->set('Foo', FooBuilder::build());
$container->set('Foo', ['app\helper\FooBuilder', 'build']);
$foo = $container->get('Foo');
```
As you can see, the PHP callable is returned by the `FooBuilder::build()` method. By doing so, the person
who wants to configure the `Foo` class no longer needs to be aware of how it is built.
By doing so, the person who wants to configure the `Foo` class no longer needs to be aware of how it is built.
Registering Dependencies <span id="registering-dependencies"></span>