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