Issues (217)

src/lib.inc.php (1 issue)

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * PHPPgAdmin 6.1.3
5
 */
6
7
use Slim\App;
8
9
\defined('BASE_PATH') || \define('BASE_PATH', \dirname(__DIR__));
10
11
\defined('THEME_PATH') || \define('THEME_PATH', \dirname(__DIR__) . '/assets/themes');
12
// Enforce PHP environment
13
\ini_set('arg_separator.output', '&amp;');
14
15
if (!\is_writable(\dirname(__DIR__) . '/temp')) {
16
    die('Your temp folder must have write permissions (use chmod 777 temp -R on linux)');
17
}
18
19
require_once \dirname(__DIR__) . '/vendor/autoload.php';
20
21
$shouldSetSession = (\defined('PHP_SESSION_ACTIVE') ? \PHP_SESSION_ACTIVE !== \session_status() : !\session_id())
22
    && !\headers_sent()
23
    && !\ini_get('session.auto_start');
24
25
if ($shouldSetSession && \PHP_SAPI !== 'cli') {
26
    \session_set_cookie_params(0, '/', $_SERVER['HTTP_HOST'], isset($_SERVER['HTTPS']));
27
    \session_name('PPA_ID');
28
    \session_start();
29
}
30
31
\defined('ADODB_ERROR_HANDLER_TYPE') || \define('ADODB_ERROR_HANDLER_TYPE', \E_USER_ERROR);
32
\defined('ADODB_ERROR_HANDLER') || \define('ADODB_ERROR_HANDLER', '\PHPPgAdmin\ADOdbException::adodb_throw');
33
34
function getAppInstance(): \Slim\App
35
{
36
    $subfolder = '';
37
    // Check to see if the configuration file exists, if not, explain
38
    if (!\file_exists(\dirname(__DIR__) . '/config.inc.php')) {
39
        die('Configuration error: Copy config.inc.php-dist to config.inc.php and edit appropriately.');
40
    }
41
    $conf = [];
42
43
    include_once \dirname(__DIR__) . '/config.inc.php';
44
45
    if (isset($conf['subfolder']) && \is_string($conf['subfolder'])) {
46
        $subfolder = $conf['subfolder'];
47
    } elseif (\PHP_SAPI === 'cli-server') {
48
        $subfolder = '/index.php';
49
    } elseif (isset($_SERVER['DOCUMENT_ROOT'])) {
50
        $subfolder = \str_replace(
51
            $_SERVER['DOCUMENT_ROOT'],
52
            '',
53
            \dirname(__DIR__)
54
        );
55
    }
56
57
    $conf['subfolder'] = $subfolder;
58
59
    $conf['debugmode'] = (!isset($conf['debugmode'])) ? false : (bool) ($conf['debugmode']);
60
61
    if ($conf['debugmode']) {
62
        \ini_set('display_startup_errors', 'On');
63
        \ini_set('opcache.revalidate_freq', '0');
64
        \error_reporting(\E_ALL);
65
66
        if (\array_key_exists('register_debuggers', $conf) && \is_callable($conf['register_debuggers'])) {
67
            $conf['register_debuggers']();
68
        }
69
    }
70
71
    $conf['BASE_PATH'] = BASE_PATH;
72
    $conf['theme_path'] = BASE_PATH . '/assets/themes';
73
    \defined('IN_TEST') || \define('IN_TEST', false);
74
    $conf['IN_TEST'] = IN_TEST;
75
    \defined('ADODB_ASSOC_CASE') || \define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE);
76
77
    // Fetch App and DI Container
78
    $app = \PHPPgAdmin\ContainerUtils::getAppInstance($conf);
79
80
    return $app;
81
}
82
83
function containerInstance(): \PHPPgAdmin\ContainerUtils
84
{
85
    $app = getAppInstance();
86
    $container = $app->getContainer();
87
88
    if (!$container instanceof \PHPPgAdmin\ContainerUtils) {
89
        \trigger_error('App Container must be an instance of \\Slim\\Container', \E_USER_ERROR);
90
    }
91
92
    return  $container;
93
}
94
95
function requestInstance(): \Slim\Http\Request
96
{
97
    return  \containerInstance()->request;
98
}
99
100
function responseInstance(): \Slim\Http\Response
101
{
102
    return \containerInstance()->response;
103
}
104