Issues (2407)

engine/instance.php (7 issues)

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 193 and the first side effect is on line 18.

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
/* 	Divine CMS - Open source CMS for widespread use.
3
    Copyright (c) 2019 Mykola Burakov ([email protected])
4
    See SOURCE.txt for other and additional information.
5
    This file is part of Divine CMS.
6
    This program is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
10
    This program is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
    GNU General Public License for more details.
14
    You should have received a copy of the GNU General Public License
15
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17
// Registry
18
$registry = new \Divine\Engine\Core\Registry();
19
20
// Config
21
$config = new \Divine\Engine\Library\Config();
22
$config->load('common');
23
$config->load($application_config);
24
$registry->set(
25
    'config',
26
    $config
27
);
28
29
// Session Handler Properties Object
30
$dbhProperties = new \RememberMe\Properties();
31
32
// $dbhProperties->setCookie("");
33
$dbhProperties->setTableSess("sessions");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal sessions does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
34
// table name that you already save your users data
35
$dbhProperties->setTableUsers("session_users");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal session_users does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
36
$dbhProperties->setTableAutologin("session_autologin");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal session_autologin does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
37
// $dbhProperties->setColSid("");
38
// $dbhProperties->setColExpiry("");
39
// $dbhProperties->setColUkey("");
40
// $dbhProperties->setSessUkey("");
41
// column that save username,email or any id of your users in tbl_users
42
$dbhProperties->setColUsername("username");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal username does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
43
// $dbhProperties->setColData("");
44
// $dbhProperties->setColToken("");
45
// $dbhProperties->setColCreated("");
46
// $dbhProperties->setColUsed("");
47
// $dbhProperties->setSessPersist("");
48
// $dbhProperties->setSessUname("");
49
// $dbhProperties->setSessAuth("");
50
// $dbhProperties->setSessRevalid("");
51
52
$dbhProperties->setDb(
53
    $config->get('db_username'),
54
    $config->get('db_password'),
55
    $config->get('db_database'),
56
    $config->get('db_hostname')
57
);
58
59
// $dbhProperties->setUseTransactions("");
60
$dbhProperties->setCollectGarbage(true);
61
$dbhProperties->setLifetimeDays("365");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 365 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
62
63
$registry->set(
64
    'dbhProperties',
65
    $dbhProperties
66
);
67
68
// Session
69
$session = new \Divine\Engine\Library\Session($registry);
70
if ($config->get('session_autostart')) {
71
    $session->start();
72
}
73
$registry->set(
74
    'session',
75
    $session
76
);
77
78
// Tracy Debugger
79
if (defined('SR_TRACY_DEBUG') && SR_TRACY_DEBUG == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
80
    \Tracy\Debugger::enable(
81
        \Tracy\Debugger::DEVELOPMENT,
82
        $_SERVER['DOCUMENT_ROOT'] . '/storage/logs/'
83
    );
84
85
    // PerformancePanel
86
    \Tracy\Debugger::getBar()
87
        ->addPanel(new \Zarganwar\PerformancePanel\Panel());
88
    \Tracy\Debugger::$showLocation = true;
89
    \Tracy\Debugger::$strictMode = true;
90
    \Tracy\Debugger::$maxLength = 500;
91
92
    // Register opencart panels (Tracy Plugins)
93
    $panels = new \TracyPanel\Plugin();
94
95
    // Clear last session about Tracy
96
    if (isset($_SESSION['_tracy']['templates_log'])) {
97
        unset($_SESSION['_tracy']['templates_log']);
98
    }
99
    if (isset($_SESSION['_tracy']['sql_log'])) {
100
        unset($_SESSION['_tracy']['sql_log']);
101
    }
102
}
103
104
// Loader
105
$loader = new \Divine\Engine\Core\Loader($registry);
106
$registry->set(
107
    'load',
108
    $loader
109
);
110
111
// Request
112
$request = new \Divine\Engine\Library\Request();
113
$registry->set(
114
    'request',
115
    $request
116
);
117
118
// Response
119
$response = new \Divine\Engine\Library\Response();
120
$response->addHeader('Content-Type: text/html; charset=utf-8');
121
$registry->set(
122
    'response',
123
    $response
124
);
125
126
// Database
127
$db = new \Divine\Engine\Library\Db(
128
    $config->get('db_hostname'),
129
    $config->get('db_username'),
130
    $config->get('db_password'),
131
    $config->get('db_database')
132
);
133
if ($config->get('db_autostart')) {
134
    $registry->set(
135
        'db',
136
        $db
137
    );
138
}
139
140
// Doctrine DBAL
141
$dbal_obj = new \Doctrine\DBAL\Configuration();
142
$dbal_conn = array(
143
    'dbname' => $config->get('db_database'),
144
    'user' => $config->get('db_username'),
145
    'password' => $config->get('db_password'),
146
    'host' => $config->get('db_hostname'),
147
    'driver' => 'pdo_mysql',
148
);
149
$dbal_qb = \Doctrine\DBAL\DriverManager::getConnection($dbal_conn, $dbal_obj)
150
    ->createQueryBuilder();
151
$registry->set(
152
    'dbal',
153
    $dbal_qb
154
);
155
156
// Cache
157
$cache = new \Divine\Engine\Library\RedisCache();
158
$registry->set(
159
    'cache',
160
    $cache
161
);
162
163
// Url
164
$url = new \Divine\Engine\Library\Url(
165
    $config->get('app_url')
166
);
167
$registry->set(
168
    'url',
169
    $url
170
);
171
172
// Language
173
$language = new \Divine\Engine\Library\Language(
174
    $config->get('language_default')
175
);
176
$language->load(
177
    $config->get('language_default')
178
);
179
$registry->set(
180
    'language',
181
    $language
182
);
183
184
// Document
185
$document = new \Divine\Engine\Library\Document();
186
$registry->set(
187
    'document',
188
    $document
189
);
190
191
// Mobile Detect
192
$detect = new \Mobile_Detect();
193
define('SR_IS_MOBILE', $detect->isMobile(), false);
194
define('SR_IS_TABLET', $detect->isTablet(), false);
195
196
// Front Controller
197
$controller = new \Divine\Engine\Core\Front($registry);
198
199
// Pre Actions
200
if ($config->has('action_pre_action')) {
201
    foreach ($config->get('action_pre_action') as $value) {
202
        $controller->addPreAction(
203
            new \Divine\Engine\Core\Action($value)
204
        );
205
    }
206
}
207
208
// Dispatch
209
$action_router = new \Divine\Engine\Core\Action(
210
    $config->get('action_router')
211
);
212
$action_error = new \Divine\Engine\Core\Action(
213
    $config->get('action_error')
214
);
215
$controller->dispatch(
216
    $action_router,
217
    $action_error
218
);
219
220
// Output
221
$response->output();
222