Failed Conditions
Pull Request — master (#332)
by Ramiro
02:20
created

config.example.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @file
5
 * A single location to store configuration.
6
 */
7
8
9
# EDIT ME PLEASE
10
11
// mysql db name
12
define('SYS_DB_NAME', '#SYS_DB_NAME#');
13
// mysql username
14
define('SYS_DB_USER', '#SYS_DB_USER#');
15
// mysql password
16
define('SYS_DB_PSWD', '#SYS_DB_PSWD#');
17
// mysql server name
18
define('SYS_DB_HOST', '#SYS_DB_HOST#');
19
// mysql server port
20
define('SYS_DB_PORT', 3306);
21
22
23
# Please, do not touch me, I'm fine ;)
24
25
// full path
26
define('SYS_PATH', realpath(dirname(__FILE__)));
27
// user session variable name
28
define('SYS_USESS_VAR', 'usrSessVal');
29
// debug mode
30
define('SYS_DEVELOPMENT_MODE', false);
31
32
33
if (directory() != '') {
34
	$subdirectory = '/'.directory().'/';
35
} else {
36
	$subdirectory = '/';
37
}
38
39
if (isset($_SERVER['HTTP_HOST'])) {
40
	if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
41
		define('HOST_URL', $_SERVER['HTTP_X_FORWARDED_PROTO'].'://'.$_SERVER['HTTP_HOST'].$subdirectory);
42
	} else if (isset($_SERVER['REQUEST_SCHEME'])) {
43
		define('HOST_URL', $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$subdirectory);
44
	} else {
45
		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
46
			define('HOST_URL', 'https://'.$_SERVER['HTTP_HOST'].$subdirectory);
47
		} else {
48
			define('HOST_URL', 'http://'.$_SERVER['HTTP_HOST'].$subdirectory);
49
		}
50
	}
51
}
52
53
## Subdirectory trick
54
function directory()
0 ignored issues
show
directory 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...
55
{
56
	##https://stackoverflow.com/questions/2090723/how-to-get-the-relative-directory-no-matter-from-where-its-included-in-php
57
	return substr(str_replace('\\', '/', realpath(dirname(__FILE__))), strlen(str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']))));
58
}
59