forked from ralphschindler/Zend_DI-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-12.php
30 lines (23 loc) · 884 Bytes
/
example-12.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
<?php
// bootstrap
include 'zf2bootstrap' . ((stream_resolve_include_path('zf2bootstrap.php')) ? '.php' : '.dist.php');
// must register autoloader
spl_autoload_register(function ($class) {
if (strpos($class, 'Foo\Bar') !== 0) {
return;
}
include_once __DIR__ . '/12/' . str_replace('\\', '/', substr($class, 7)) . '.php';
});
// compile phase
$compiler = new Zend\Di\Definition\CompilerDefinition();
$compiler->getIntrospectionStrategy()->setUseAnnotations(true); // TURN ANNOTATIONS ON
$compiler->addDirectory(__DIR__ . '/12/');
$compiler->compile();
$arrayDef = $compiler->toArrayDefinition();
$definitions = new Zend\Di\DefinitionList($arrayDef);
$di = new Zend\Di\Di($definitions);
$baz = $di->get('Foo\Bar\Baz');
// expression to test
$works = ($baz->bam instanceof Foo\Bar\Bam);
// display result
echo (($works) ? 'It works!' : 'It DOES NOT work!');