-
Notifications
You must be signed in to change notification settings - Fork 22
/
example-04.php
45 lines (38 loc) · 1.11 KB
/
example-04.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
<?php
namespace MovieApp {
class Lister {
public $dbFinder;
public function __construct(DbFinder $dbFinder){
$this->dbFinder = $dbFinder;
}
}
class DbFinder {
public $username, $password = null;
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}
}
}
namespace {
// bootstrap
include 'zf2bootstrap' . ((stream_resolve_include_path('zf2bootstrap.php')) ? '.php' : '.dist.php');
$di = new Zend\Di\Di;
$di->instanceManager()->setParameters(
'MovieApp\DbFinder',
array(
'username' => 'my-username',
'password' => 'my-password'
)
);
$lister = $di->get('MovieApp\Lister');
// expression to test
$works = (
$lister->dbFinder instanceof MovieApp\DbFinder
&& $lister->dbFinder->username == 'my-username'
&& $lister->dbFinder->password == 'my-password'
);
// display result
echo (($works) ? 'It works!' : 'It DOES NOT work!') . PHP_EOL;
}