1 | <?php |
||
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', '&'); |
||
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.'); |
||
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return Slim\App . Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
![]() |
|||
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 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.