Completed
Push — 2.0 ( b5ef61...2c7009 )
by Marco
12:59 queued 12s
created

Database::init()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 3
eloc 5
nc 2
nop 1
1
<?php namespace Comodojo\Extender\Components;
2
3
use \Comodojo\Dispatcher\Components\Configuration;
4
use \Doctrine\DBAL\Configuration as DoctrineConfiguration;
5
use \Doctrine\DBAL\DriverManager;
6
use \Exception;
7
8
/**
9
 * Lock file manager (static methods)
10
 *
11
 * @package     Comodojo extender
12
 * @author      Marco Giovinazzi <[email protected]>
13
 * @license     GPL-3.0+
14
 *
15
 * LICENSE:
16
 *
17
 * This program is free software: you can redistribute it and/or modify
18
 * it under the terms of the GNU Affero General Public License as
19
 * published by the Free Software Foundation, either version 3 of the
20
 * License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU Affero General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Affero General Public License
28
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29
 */
30
31
class Database {
32
33
    public static function init(Configuration $configuration) {
34
        
35
        $dbspecs = $configuration->get('database');
36
        
37
        if ( empty($dbspecs) || !is_array($dbspecs) ) throw new Exception("Empty database connection parameters");
38
        
39
        $config = new DoctrineConfiguration();
40
        
41
        return DriverManager::getConnection($dbspecs, $config);
42
        
43
    }
44
45
}
46