Completed
Push — master ( f3c356...547666 )
by Matteo
01:41
created

Mysql::getManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Mattbit\MysqlCompat;
4
5
/**
6
 * Class Mysql
7
 * Provides a facade to access the Mysql functions using a Manager singleton.
8
 */
9
class Mysql
10
{
11
    /**
12
     * The database manager service.
13
     *
14
     * @var Manager
15
     */
16
    private static $manager;
17
18
    /**
19
     * The bridge service.
20
     *
21
     * @var Bridge
22
     */
23
    private static $bridge;
24
25
    /**
26
     * Forward static calls to the bridge singleton.
27
     *
28
     * @param  $method
29
     * @param  $args
30
     *
31
     * @return mixed
32
     */
33
    public static function __callStatic($method, $args)
34
    {
35
        if (self::$bridge === null) {
36
            $manager = self::getManager();
37
            self::$bridge = new Bridge($manager);
38
        }
39
40
        return call_user_func_array([self::$bridge, $method], $args);
41
    }
42
43
    /**
44
     * Get the database manager.
45
     *
46
     * @return Manager
47
     */
48
    public static function getManager()
49
    {
50
        if (self::$manager === null) {
51
            self::$manager = new Manager(new ConnectionFactory());
52
        }
53
54
        return self::$manager;
55
    }
56
57
    /**
58
     * Defines the old global functions and constants.
59
     *
60
     * @return void
61
     */
62
    public static function defineGlobals()
63
    {
64
        require_once __DIR__ . '/globals.php';
65
    }
66
}
67