-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathlaminas-servicemanager.php
55 lines (44 loc) · 2.32 KB
/
laminas-servicemanager.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
<?php
declare(strict_types=1);
use Doctrine\ORM\EntityManagerInterface;
use Laminas\ServiceManager\ServiceManager;
use Roave\PsrContainerDoctrine\EntityManagerFactory;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';
// Standard config keys
$minimalConfig = require __DIR__ . '/minimal-config.php';
$dependencies = [];
$dependencies['factories']['doctrine.entity_manager.orm_default'] = EntityManagerFactory::class;
$dependencies['services']['config'] = $minimalConfig;
$container = new ServiceManager($dependencies);
$object = $container->get('doctrine.entity_manager.orm_default');
if (is_object($object)) {
echo $object::class . "\n"; // Doctrine\ORM\EntityManager
}
// Custom config keys
$customKeyConfig = require __DIR__ . '/minimal-config-custom-key.php';
$dependencies = [];
$dependencies['factories']['doctrine.entity_manager.orm_custom_key'] = new EntityManagerFactory('orm_custom_key');
$dependencies['services']['config'] = $customKeyConfig;
$container = new ServiceManager($dependencies);
$object = $container->get('doctrine.entity_manager.orm_custom_key');
if (is_object($object)) {
echo $object::class . "\n"; // Doctrine\ORM\EntityManager
}
// Full config
$fullConfig = require __DIR__ . '/full-config.php';
$dependencies = $fullConfig['dependencies'];
$dependencies['services']['config'] = $fullConfig;
$container = new ServiceManager($dependencies);
$object = $container->get(EntityManagerInterface::class);
if (is_object($object)) {
echo $object::class . "\n"; // Doctrine\ORM\EntityManager
}
$object = $container->get('doctrine.entity_manager.orm_default_with_url');
if (is_object($object)) {
echo $object::class . "\n"; // Doctrine\ORM\EntityManager
}
$object = $container->get('doctrine.entity_manager.orm_default_with_array');
if (is_object($object)) {
echo $object::class . "\n"; // Doctrine\ORM\EntityManager
}