/
test.php
54 lines (42 loc) · 2.24 KB
/
test.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
<?php
define('DS', DIRECTORY_SEPARATOR);
/* Include the container */
include_once 'Core'.DS.'Services'.DS.'zsServiceContainer.php';
/* Include your business classes */
function __autoload($className) {
if(is_file($path = 'Model'.DS.$className.'.php'))
include_once $path;
}
/********************************************************************************************/
/******************* XML file configuration ********************/
/******************* The easiest way to access your services ********************/
/********************************************************************************************/
/* The service definitions will be loaded from the xml config file passed in argument */
$container = new zsServiceContainer ('Core/Conf/config.xml');
/* We retrieve our orm singleton instance */
$orm = $container->getService('orm');
/********************************************************************************************/
/******************* PHP service definition ********************/
/********************************************************************************************/
/* Service definition with arguments passed to the constructor */
$dbAdapter = new zsServiceDefinition('zsPdo', array( 'mysql:localhost', 'dbUser', 'dbPassword', null ) );
$dbAdapter ->setId('dbAdapter')
->setGlobal(true);
/* Service definition with dependency injection in the constructor */
$dataSource = new zsServiceDefinition('zsDb', array(new zsServiceReference('dbAdapter')));
$dataSource ->setId('dataSource')
->setGlobal(true);
/* Service definition with depedndency injected by "setter" in the property "_dataSource" */
$orm = new zsServiceDefinition('zsOrm');
$orm->setId('orm')
->addDependence('_dataSource', new zsServiceReference('dataSource'))
->setGlobal(true);
/* Container creation with service definitions passed in the constructor, no config file passed */
$container = new zsServiceContainer ( null,
array( 'orm' => $orm,
'dataSource' => $dataSource,
'dbAdapter' => $dbAdapter )
);
/* We retrieve our orm singleton instance */
$orm = $container->getService('orm');
?>