Skip to content

Commit d2884d9

Browse files
committed
formatting
1 parent 32be441 commit d2884d9

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

container.md

+8-11
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,14 @@ As you can see, the object being resolved will be passed to the callback, allowi
256256
<a name="psr-11"></a>
257257
## PSR-11
258258

259-
Laravel's service container is compliant with PSR-11. The method `has` is an alias for `bound` and will answer whether an identifier is known to the container or not. As for the implementation of `get`, it will be slightly different than `resolve` because it will not offer auto-wiring. Calling `get` with an unknown identifier will still throw an exception even if the identifier is a concrete class.
259+
Laravel's service container implements the [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md) interface. Therefore, you may type-hint the PSR-11 container interface to obtain an instance of the Laravel container:
260260

261-
namespace Some\Package;
261+
use Psr\Container\ContainerInterface;
262262

263-
class Foo
264-
{
265-
//
266-
}
263+
Route::get('/', function (ContainerInterface $container) {
264+
$service = $container->get('Service');
265+
266+
//
267+
});
267268

268-
// Throws Psr\Container\Exception\NotFoundExceptionInterface
269-
$foo = $this->app->get(Foo::class);
270-
271-
// $foo is auto-wired into an instance of Foo
272-
$foo = $this->app->resolve(Foo::class);
269+
> {note} Calling the `get` method will throw an exception if the identifier has not been explicitly bound into the container.

0 commit comments

Comments
 (0)