Conditions | 4 |
Paths | 6 |
Total Lines | 39 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function createService(ServiceLocatorInterface $serviceLocator) |
||
29 | { |
||
30 | /** @var Config $config */ |
||
31 | $config = ServiceLocator::instance()->get(Config::class); |
||
32 | |||
33 | $type = $config->get('db:type'); |
||
34 | $name = $config->get('db:name'); |
||
35 | $user = $config->get('db:username'); |
||
36 | $pass = $config->get('db:password'); |
||
37 | $host = $config->get('db:host') ?: 'localhost'; |
||
38 | $port = ''; |
||
39 | |||
40 | $attributes = []; |
||
41 | |||
42 | if ($type === 'mysql') { |
||
43 | |||
44 | $attributes = [ |
||
45 | \PDO::MYSQL_ATTR_INIT_COMMAND => "SET sql_mode ='ANSI_QUOTES', NAMES utf8", |
||
46 | \PDO::ATTR_EMULATE_PREPARES => false, |
||
47 | ]; |
||
48 | |||
49 | $port = $config->get('db:port') ?: 3306; |
||
50 | |||
51 | } |
||
52 | |||
53 | $dbConf = new DbConfig( |
||
54 | $type, |
||
55 | $name, |
||
56 | $user, |
||
57 | $pass, |
||
58 | $host, |
||
59 | $port, |
||
60 | $attributes |
||
61 | ); |
||
62 | |||
63 | $entityManager = new EntityManager([EntityManager::OPT_CONNECTION => $dbConf]); |
||
64 | |||
65 | return new ORM($entityManager); |
||
66 | } |
||
67 | |||
68 | } |