Config::getDBConfig()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace conf;
4
5
/**
6
 * Main configuration.
7
 *
8
 * @category Asymptix PHP Framework
9
 * @author Dmytro Zarezenko <[email protected]>
10
 * @copyright (c) 2009 - 2017, Dmytro Zarezenko
11
 * @license http://opensource.org/licenses/MIT
12
 */
13
class Config {
14
    /**
15
     * Basic params
16
     */
17
    const SITE_TITLE = "Site title";
18
19
    /**
20
     * E-mail configuration
21
     */
22
    const EMAIL_ADMIN = "[email protected]";
23
    const EMAIL_FROM = "[email protected]";
24
    const EMAIL_FROM_NAME = "From name";
25
    const EMAIL_TPL_FOLDER = "templates/email/";
26
    const EMAIL_SIGNATURE_TPL = "signature.tpl.php";
27
28
    /**
29
     * Detects if system runned on the local webserver.
30
     *
31
     * @return boolean
32
     */
33
    public static function isDevServer() {
0 ignored issues
show
Coding Style introduced by
isDevServer uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
34
        return ($_SERVER['SERVER_ADDR'] == '127.0.0.1');
35
    }
36
37
    /**
38
     * Database configuration.
39
     * You can add additional configurations associated by hostname as an array
40
     * key.
41
     *
42
     * @var array
43
     */
44
    public static $db = [
45
        'default' => [
46
            'HOST' => "localhost",
47
            'DBNAME' => "dbname",
48
            'USER' => "root",
49
            'PASSWORD' => "pass",
50
            'DB_CHARSET' => "utf8"
51
        ]
52
    ];
53
54
    /**
55
     * Returns database configuration for current hostname.
56
     *
57
     * @return array
58
     */
59
    public static function getDBConfig() {
0 ignored issues
show
Coding Style introduced by
getDBConfig uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
60
        if (isset($_SERVER['HTTP_HOST']) && isset(self::$db[$_SERVER['HTTP_HOST']])) {
61
            return self::$db[$_SERVER['HTTP_HOST']];
62
        }
63
        return self::$db['default'];
64
    }
65
66
    /**
67
     * Returns database configuration parameter.
68
     *
69
     * @param string $paramName Parameter name.
70
     * @return string
71
     */
72
    public static function getDBConfigParam($paramName) {
73
        $dbConfig = self::getDBConfig();
74
        if (isset($dbConfig) && isset($dbConfig[$paramName])) {
75
            return $dbConfig[$paramName];
76
        }
77
        return "";
78
    }
79
80
    /**
81
     * FS
82
     */
83
    const DIR_UPLOADS = "uploads/";
84
    const DIR_AVATARS = "uploads/avatars/";
85
86
    /**
87
     * UI
88
     */
89
    const ITEMS_PER_PAGE = 15;
90
91
    /**
92
     * You can add you custom parameters here.
93
     */
94
95
}
96