forked from ralphschindler/Zend_DI-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-15.php
56 lines (50 loc) · 1.58 KB
/
example-15.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
54
55
56
<?php
namespace System {
class Mapper {
public $drivers;
public function addDriver(Driver $driver, $name){
$this->drivers[] = array($driver, $name);
}
}
interface Driver {
}
}
namespace DifferentNs {
class DriverOne implements \System\Driver {}
class DriverTwo implements \System\Driver {}
}
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(
'System\Mapper' => array(
'addDriver' => array(
'driver' => array('type' => 'System\Driver', 'required' => true),
'name' => array('required' => true)
)
)
)
),
'instance' => array(
'System\Mapper' => array(
'injections' => array(
'addDriver' => array(
array('driver' => 'DifferentNs\DriverOne', 'name' => 'foo'),
array('driver' => 'DifferentNs\DriverTwo', 'name' => 'bar')
)
)
)
)
)));
$mapper = $di->get('System\Mapper');
// expression to test
$works = (
$mapper->drivers[0][0] instanceof DifferentNs\DriverOne
&& $mapper->drivers[1][0] instanceof DifferentNs\DriverTwo
);
// display result
echo (($works) ? 'It works!' : 'It DOES NOT work!');
}