Skip to content

Commit c4bb876

Browse files
authored
Update README.md
1 parent 50d5113 commit c4bb876

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

README.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,60 @@
33

44
This class is a basic implementation of a Container. It is inspired by PSR-11 Container Interface but with stripped down with a bare minimum feature for maximum compatibility within the WordPress ecosystem!
55

6-
This Container contains only one class than can easily be copied, modified, and adjusted to your needs.
6+
This Container contains only one class than can easily be copied, modified, and adjusted to your needs. This class is designed to be a drop-in class for any plugin or theme.
77

88
Supports PHP 5.6 or above and Autowiring.
99

10+
11+
12+
13+
## Installation
14+
- Rename the class by modifying the namespace and/or the class name.
15+
- Use it! See usage below.
1016
## Usage
1117

1218
```php
1319
// Require the Container class file.
1420
require_once __DIR__ . '/class-container.php';
1521

16-
// Instantiate.
17-
$container = new Container();
22+
// Instantiate. Replace the class name with your own.
23+
$container = new DIC\WP\Container();
1824
```
1925

26+
## Example Usage
27+
28+
Without this class we would have to wire our dependencies like the following:
29+
30+
```php
31+
// Say we have 4 classes,
32+
// Foo which has Bar and Zag dependencies,
33+
// Bar with Zig dependency,
34+
// Zig, and Zag without any dependencies.
35+
36+
class Foo {
37+
protected $bar;
38+
protected $zag;
39+
public function __construct( Bar $bar, Zag $zag ) {
40+
$this->bar = $bar;
41+
$this->zag = $zag;
42+
}
43+
}
44+
45+
class Bar {
46+
protected $zig;
47+
public function __construct( Zig $zig ) {
48+
$this->zig = $zig;
49+
}
50+
}
51+
52+
class Zig {
53+
// ...
54+
}
55+
56+
class Zag {
57+
// ...
58+
}
59+
60+
$foo = new Foo( new Bar( new Baz() ), new Zag() );
61+
```
2062

0 commit comments

Comments
 (0)