You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-3Lines changed: 45 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3,18 +3,60 @@
3
3
4
4
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!
5
5
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.
7
7
8
8
Supports PHP 5.6 or above and Autowiring.
9
9
10
+
11
+
12
+
13
+
## Installation
14
+
- Rename the class by modifying the namespace and/or the class name.
15
+
- Use it! See usage below.
10
16
## Usage
11
17
12
18
```php
13
19
// Require the Container class file.
14
20
require_once __DIR__ . '/class-container.php';
15
21
16
-
// Instantiate.
17
-
$container = new Container();
22
+
// Instantiate. Replace the class name with your own.
23
+
$container = new DIC\WP\Container();
18
24
```
19
25
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() );
0 commit comments