forked from ralphschindler/Zend_DI-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-08.php
53 lines (47 loc) · 1.38 KB
/
example-08.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Application {
class Page {
public $blocks;
public function addBlock(Block $block){
$this->blocks[] = $block;
}
}
interface Block {
}
}
namespace DifferentNs {
class BlockOne implements \Application\Block {}
class BlockTwo implements \Application\Block {}
}
namespace {
// bootstrap
include 'zf2bootstrap' . ((stream_resolve_include_path('zf2bootstrap.php')) ? '.php' : '.dist.php');
$di = new Zend\Di\Di;
$di->configure(new Zend\Di\Configuration(array(
'definition' => array(
'class' => array(
'Application\Page' => array(
'addBlock' => array(
'block' => array('type' => 'Application\Block', 'required' => true)
)
)
)
),
'instance' => array(
'Application\Page' => array(
'injections' => array(
'DifferentNs\BlockOne',
'DifferentNs\BlockTwo'
)
)
)
)));
$page = $di->get('Application\Page');
// expression to test
$works = (
$page->blocks[0] instanceof DifferentNs\BlockOne
&& $page->blocks[1] instanceof DifferentNs\BlockTwo
);
// display result
echo (($works) ? 'It works!' : 'It DOES NOT work!') . PHP_EOL;
}