Skip to content

Commit 74bac50

Browse files
author
Phil Bennett
committed
Improve code examples in docs
1 parent 041c52d commit 74bac50

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

docs/5.x/attribute-resolution.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace Acme;
3333

3434
use League\Container\Attribute\Inject;
3535

36-
class Bar {
36+
class Bar
37+
{
3738
public function hello(): string
3839
{
3940
return 'hello';
@@ -43,14 +44,12 @@ class Bar {
4344
class Foo
4445
{
4546
public function __construct(
46-
#[Inject('bar')] Bar $bar
47+
#[Inject(Bar::class)] public Bar $bar
4748
) {
48-
$this->bar = $bar;
4949
}
5050
}
5151

5252
$container = new League\Container\Container();
53-
$container->add('bar', new Bar());
5453
$container->delegate(new League\Container\ReflectionContainer());
5554

5655
$foo = $container->get(Foo::class);
@@ -64,8 +63,6 @@ echo $foo->bar->hello(); // 'hello'
6463

6564
use League\Container\Attribute\Resolve;
6665

67-
class Bar {}
68-
6966
class Config {
7067
public array $settings = [
7168
'db' => [
@@ -78,13 +75,12 @@ class Config {
7875
class Baz
7976
{
8077
public function __construct(
81-
#[Resolve('config', 'settings.db.host')] public string $dbHost
78+
#[Resolve(Config::class, 'settings.db.host')] public string $dbHost
8279
) {
8380
}
8481
}
8582

8683
$container = new League\Container\Container();
87-
$container->add('config', new Config());
8884
$container->delegate(new League\Container\ReflectionContainer());
8985

9086
$baz = $container->get(Baz::class);

docs/unstable/attribute-resolution.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace Acme;
3333

3434
use League\Container\Attribute\Inject;
3535

36-
class Bar {
36+
class Bar
37+
{
3738
public function hello(): string
3839
{
3940
return 'hello';
@@ -43,14 +44,12 @@ class Bar {
4344
class Foo
4445
{
4546
public function __construct(
46-
#[Inject('bar')] Bar $bar
47+
#[Inject(Bar::class)] public Bar $bar
4748
) {
48-
$this->bar = $bar;
4949
}
5050
}
5151

5252
$container = new League\Container\Container();
53-
$container->add('bar', new Bar());
5453
$container->delegate(new League\Container\ReflectionContainer());
5554

5655
$foo = $container->get(Foo::class);
@@ -64,8 +63,6 @@ echo $foo->bar->hello(); // 'hello'
6463

6564
use League\Container\Attribute\Resolve;
6665

67-
class Bar {}
68-
6966
class Config {
7067
public array $settings = [
7168
'db' => [
@@ -78,13 +75,12 @@ class Config {
7875
class Baz
7976
{
8077
public function __construct(
81-
#[Resolve('config', 'settings.db.host')] public string $dbHost
78+
#[Resolve(Config::class, 'settings.db.host')] public string $dbHost
8279
) {
8380
}
8481
}
8582

8683
$container = new League\Container\Container();
87-
$container->add('config', new Config());
8884
$container->delegate(new League\Container\ReflectionContainer());
8985

9086
$baz = $container->get(Baz::class);

0 commit comments

Comments
 (0)