forked from ralphschindler/Zend_DI-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-17.php
45 lines (36 loc) · 1.08 KB
/
example-17.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
<?php
namespace MovieApp {
class Lister {
public $finderA, $finderB;
public function setFinderA(Finder $finder) {
$this->finderA = $finder;
}
public function setFinderB(Finder $finder) {
$this->finderB = $finder;
}
}
class Finder {
}
}
namespace {
// bootstrap
include 'zf2bootstrap' . ((stream_resolve_include_path('zf2bootstrap.php')) ? '.php' : '.dist.php');
$di = new Zend\Di\Di;
$di->instanceManager()->setParameters(
'MovieApp\Lister',
array(
'MovieApp\Lister::setFinderA:finder' => new MovieApp\Finder,
'MovieApp\Lister::setFinderB:finder' => function () {
return new MovieApp\Finder;
}
)
);
$lister = $di->get('MovieApp\Lister');
// expression to test
$works = ($lister->finderA instanceof MovieApp\Finder
&& $lister->finderB instanceof MovieApp\Finder
&& $lister->finderA !== $lister->finderB
);
// display result
echo (($works) ? 'It works!' : 'It DOES NOT work!');
}