Passed
Push — master ( 68c244...b86a9b )
by Thierry
02:28
created

Jaxon::upload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Jaxon.php - Jaxon class
5
 *
6
 * The Jaxon class uses a modular plug-in system to facilitate the processing
7
 * of special Ajax requests made by a PHP page.
8
 * It generates Javascript that the page must include in order to make requests.
9
 * It handles the output of response commands (see <Jaxon\Response\Response>).
10
 * Many flags and settings can be adjusted to effect the behavior of the Jaxon class
11
 * as well as the client-side javascript.
12
 *
13
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
14
 * @author Jared White
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
15
 * @author J. Max Wilson
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
16
 * @author Joseph Woolley
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
17
 * @author Steffen Konerow
0 ignored issues
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
18
 * @author Thierry Feuzeu <[email protected]>
19
 * @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
20
 * @copyright Copyright (c) 2008-2010 by Joseph Woolley, Steffen Konerow, Jared White  & J. Max Wilson
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
21
 * @copyright 2016 Thierry Feuzeu <[email protected]>
22
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
23
 * @link https://github.com/jaxon-php/jaxon-core
24
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
25
26
namespace Jaxon;
27
28
use Jaxon\App\App;
29
use Jaxon\App\Bootstrap;
30
use Jaxon\App\Session\SessionInterface;
31
use Jaxon\Config\ConfigManager;
32
use Jaxon\Di\Container;
33
use Jaxon\Exception\RequestException;
34
use Jaxon\Exception\SetupException;
35
use Jaxon\Plugin\Code\CodeGenerator;
36
use Jaxon\Plugin\Manager\PackageManager;
37
use Jaxon\Plugin\Manager\PluginManager;
38
use Jaxon\Plugin\Package;
39
use Jaxon\Plugin\Request\CallableClass\CallableRegistry;
40
use Jaxon\Plugin\Response\Dialog\DialogPlugin;
41
use Jaxon\Plugin\ResponsePlugin;
42
use Jaxon\Request\Call\Paginator;
43
use Jaxon\Request\Factory\Factory;
44
use Jaxon\Request\Factory\Psr\PsrFactory;
45
use Jaxon\Request\Factory\RequestFactory;
46
use Jaxon\Request\Handler\CallbackManager;
47
use Jaxon\Request\Handler\UploadHandler;
48
use Jaxon\Response\Manager\ResponseManager;
49
use Jaxon\Response\Response;
50
use Jaxon\Response\ResponseInterface;
51
use Jaxon\Ui\View\ViewRenderer;
52
use Jaxon\Utils\Http\UriException;
53
use Jaxon\Utils\Template\TemplateEngine;
54
use Jaxon\Utils\Translation\Translator;
55
use Psr\Log\LoggerInterface;
56
57
use function error_reporting;
58
use function gmdate;
59
use function header;
60
use function headers_sent;
61
use function ob_end_clean;
62
use function ob_get_level;
63
use function trim;
64
65
class Jaxon
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Jaxon
Loading history...
66
{
67
    /**
68
     * Package version number
69
     *
70
     * @const string
71
     */
72
    const VERSION = 'Jaxon 4.0.0-dev';
73
74
    /*
75
     * Request plugins
76
     */
0 ignored issues
show
Coding Style introduced by
Empty line required after block comment
Loading history...
77
    const CALLABLE_CLASS = 'CallableClass';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
78
    const CALLABLE_DIR = 'CallableDir';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
79
    const CALLABLE_FUNCTION = 'CallableFunction';
80
81
    /**
82
     * A static instance on this class
83
     *
84
     * @var Jaxon
85
     */
86
    private static $xInstance = null;
87
88
    /**
89
     * The DI container
90
     *
91
     * @var Container
92
     */
93
    private static $xContainer = null;
94
95
    /**
96
     * @var Bootstrap
97
     */
98
    protected $xBootstrap;
99
100
    /**
101
     * @var Translator
102
     */
103
    protected $xTranslator;
104
105
    /**
106
     * @var ConfigManager
107
     */
108
    protected $xConfigManager;
109
110
    /**
111
     * @var PluginManager
112
     */
113
    protected $xPluginManager;
114
115
    /**
116
     * @var PackageManager
117
     */
118
    protected $xPackageManager;
119
120
    /**
121
     * @var CodeGenerator
122
     */
123
    protected $xCodeGenerator;
124
125
    /**
126
     * @var CallableRegistry
127
     */
128
    protected $xClassRegistry;
129
130
    /**
131
     * @var CallbackManager
132
     */
133
    protected $xCallbackManager;
134
135
    /**
136
     * @var ResponseManager
137
     */
138
    protected $xResponseManager;
139
140
    /**
141
     * @return void
142
     */
143
    private static function initInstance()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
144
    {
145
        // Set the attributes from the container
146
        self::$xInstance->xBootstrap = self::$xContainer->g(Bootstrap::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
147
        self::$xInstance->xTranslator = self::$xContainer->g(Translator::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
148
        self::$xInstance->xConfigManager = self::$xContainer->g(ConfigManager::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
149
        self::$xInstance->xPluginManager = self::$xContainer->g(PluginManager::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
150
        self::$xInstance->xPackageManager = self::$xContainer->g(PackageManager::class);
151
        self::$xInstance->xCodeGenerator = self::$xContainer->g(CodeGenerator::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
152
        self::$xInstance->xClassRegistry = self::$xContainer->g(CallableRegistry::class);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
153
        self::$xInstance->xCallbackManager = self::$xContainer->g(CallbackManager::class);
154
        self::$xInstance->xResponseManager = self::$xContainer->g(ResponseManager::class);
155
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
156
157
    /**
158
     * Get the static instance
159
     *
160
     * @return Jaxon
161
     */
162
    public static function getInstance(): ?Jaxon
163
    {
164
        if(self::$xInstance === null)
165
        {
166
            self::$xInstance = new Jaxon();
167
            self::$xContainer = new Container(self::$xInstance);
168
            self::initInstance();
169
        }
170
        // Call the on boot callbacks on each call to the jaxon() function.
171
        self::$xInstance->xBootstrap->onBoot();
172
        return self::$xInstance;
173
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
174
175
    /**
176
     * The constructor
177
     */
178
    private function __construct()
179
    {}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
180
181
    /**
182
     * The current Jaxon version
183
     *
184
     * @return string
185
     */
186
    public function getVersion(): string
187
    {
188
        return self::VERSION;
189
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
190
191
    /**
192
     * Get the DI container
193
     *
194
     * @return Container
195
     */
196
    public function di(): ?Container
197
    {
198
        return self::$xContainer;
199
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
200
201
    /**
202
     * Get the logger
203
     *
204
     * @return LoggerInterface
205
     */
206
    public function logger(): LoggerInterface
207
    {
208
        return $this->di()->logger();
209
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
210
211
    /**
212
     * Set the value of a config option
213
     *
214
     * @param string $sName    The option name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
215
     * @param mixed $sValue    The option value
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
216
     *
217
     * @return void
218
     */
219
    public function setOption(string $sName, $sValue)
220
    {
221
        $this->xConfigManager->setOption($sName, $sValue);
222
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
223
224
    /**
225
     * Get the value of a config option
226
     *
227
     * @param string $sName    The option name
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
228
     * @param mixed|null $xDefault    The default value, to be returned if the option is not defined
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
229
     *
230
     * @return mixed
231
     */
232
    public function getOption(string $sName, $xDefault = null)
233
    {
234
        return $this->xConfigManager->getOption($sName, $xDefault);
235
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
236
237
    /**
238
     * Check the presence of a config option
239
     *
240
     * @param string $sName    The option name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
241
     *
242
     * @return bool
243
     */
244
    public function hasOption(string $sName): bool
245
    {
246
        return $this->xConfigManager->hasOption($sName);
247
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
248
249
    /**
250
     * Read the options from the file, if provided, and return the config
251
     *
252
     * @param string $sConfigFile The full path to the config file
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
253
     * @param string $sConfigSection The section of the config file to be loaded
254
     *
255
     * @return ConfigManager
256
     * @throws SetupException
257
     */
258
    public function config(string $sConfigFile = '', string $sConfigSection = ''): ConfigManager
259
    {
260
        if(!empty(($sConfigFile = trim($sConfigFile))))
0 ignored issues
show
Coding Style introduced by
Variable assignment found within a condition. Did you mean to do a comparison ?
Loading history...
261
        {
262
            $this->xConfigManager->load($sConfigFile, trim($sConfigSection));
263
        }
264
        return $this->xConfigManager;
265
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
266
267
    /**
268
     * Get the translator
269
     *
270
     * @return Translator
271
     */
272
    public function translator(): Translator
273
    {
274
        return $this->xTranslator;
275
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
276
277
    /**
278
     * Get the Response object
279
     *
280
     * @return ResponseInterface
281
     */
282
    public function getResponse(): ResponseInterface
283
    {
284
        return $this->xResponseManager->getResponse();
285
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
286
287
    /**
288
     * Create a new Jaxon response object
289
     *
290
     * @return Response
291
     */
292
    public function newResponse(): Response
293
    {
294
        return $this->di()->newResponse();
295
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
296
297
    /**
298
     * Register a plugin
299
     *
300
     * Below is a table for priorities and their description:
301
     * - 0 to 999: Plugins that are part of or extensions to the jaxon core
302
     * - 1000 to 8999: User created plugins, typically, these plugins don't care about order
303
     * - 9000 to 9999: Plugins that generally need to be last or near the end of the plugin list
304
     *
305
     * @param string $sClassName    The plugin class
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
306
     * @param string $sPluginName    The plugin name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
307
     * @param integer $nPriority    The plugin priority, used to order the plugins
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 4 found
Loading history...
308
     *
309
     * @return void
310
     * @throws SetupException
311
     */
312
    public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000)
313
    {
314
        $this->xPluginManager->registerPlugin($sClassName, $sPluginName, $nPriority);
315
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
316
317
    /**
318
     * Register a package
319
     *
320
     * @param string $sClassName    The package class
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
321
     * @param array $xPkgOptions    The user provided package options
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
322
     *
323
     * @return void
324
     * @throws SetupException
325
     */
326
    public function registerPackage(string $sClassName, array $xPkgOptions = [])
327
    {
328
        $this->xPackageManager->registerPackage($sClassName, $xPkgOptions);
329
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
330
331
    /**
332
     * Register request handlers, including functions, callable classes and directories.
333
     *
334
     * @param string $sType    The type of request handler being registered
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
335
     *        Options include:
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 8
Loading history...
336
     *        - Jaxon::CALLABLE_FUNCTION: a function declared at global scope
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 8
Loading history...
337
     *        - Jaxon::CALLABLE_CLASS: a class who's methods are to be registered
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 8
Loading history...
338
     *        - Jaxon::CALLABLE_DIR: a directory containing classes to be registered
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 8
Loading history...
339
     * @param string $sName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
340
     *        When registering a function, this is the name of the function
341
     *        When registering a callable class, this is the class name
342
     *        When registering a callable directory, this is the full path to the directory
343
     * @param array|string $xOptions    The related options
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
344
     *
345
     * @return void
346
     * @throws SetupException
347
     */
348
    public function register(string $sType, string $sName, $xOptions = [])
349
    {
350
        $this->xPluginManager->registerCallable($sType, $sName, $xOptions);
351
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
352
353
    /**
354
     * Get an instance of a registered class
355
     *
356
     * @param string $sClassName The class name
357
     *
358
     * @return null|object
359
     * @throws SetupException
360
     */
361
    public function instance(string $sClassName)
362
    {
363
        $xCallable = $this->xClassRegistry->getCallableObject($sClassName);
364
        return ($xCallable) ? $xCallable->getRegisteredObject() : null;
0 ignored issues
show
introduced by
$xCallable is of type Jaxon\Plugin\Request\CallableClass\CallableObject, thus it always evaluated to true.
Loading history...
365
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
366
367
    /**
368
     * Get the factory
369
     *
370
     * @return Factory
371
     */
372
    public function factory(): Factory
373
    {
374
        return $this->di()->getFactory();
375
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
376
377
    /**
378
     * Get the PSR factory
379
     *
380
     * @return PsrFactory
381
     */
382
    public function psr(): PsrFactory
383
    {
384
        return $this->di()->getPsrFactory();
385
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
386
387
    /**
388
     * Get a request to a registered class
389
     *
390
     * @param string $sClassName The class name
391
     *
392
     * @return RequestFactory|null
393
     * @throws SetupException
394
     */
395
    public function request(string $sClassName = ''): ?RequestFactory
396
    {
397
        return $this->factory()->request($sClassName);
398
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
399
400
    /**
401
     * Returns the Jaxon Javascript header and wrapper code to be printed into the page
402
     *
403
     * The javascript code returned by this function is dependent on the plugins
404
     * that are included and the functions and classes that are registered.
405
     *
406
     * @param bool $bIncludeJs    Also get the JS files
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
407
     * @param bool $bIncludeCss    Also get the CSS files
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
408
     *
409
     * @return string
410
     * @throws UriException
411
     */
412
    public function getScript(bool $bIncludeJs = false, bool $bIncludeCss = false): string
413
    {
414
        return $this->xCodeGenerator->getScript($bIncludeJs, $bIncludeCss);
415
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
416
417
    /**
418
     * Return the javascript header code and file includes
419
     *
420
     * @return string
421
     */
422
    public function getJs(): string
423
    {
424
        return $this->xCodeGenerator->getJs();
425
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
426
427
    /**
428
     * Return the CSS header code and file includes
429
     *
430
     * @return string
431
     */
432
    public function getCss(): string
433
    {
434
        return $this->xCodeGenerator->getCss();
435
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
436
437
    /**
438
     * Determine if a call is a jaxon request or a page load request
439
     *
440
     * @return bool
441
     */
442
    public function canProcessRequest(): bool
443
    {
444
        return $this->di()->getRequestHandler()->canProcessRequest();
445
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
446
447
    /**
448
     * If this is a jaxon request, call the requested PHP function, build the response and send it back to the browser
449
     *
450
     * This is the main server side engine for Jaxon.
451
     * It handles all the incoming requests, including the firing of events and handling of the response.
452
     * If your RequestURI is the same as your web page, then this function should be called before ANY
453
     * headers or HTML is output from your script.
454
     *
455
     * This function may exit after the request is processed, if the 'core.process.exit' option is set to true.
456
     *
457
     * @return void
458
     *
459
     * @throws RequestException
460
     * @see <Jaxon\Jaxon->canProcessRequest>
461
     */
462
    public function processRequest()
463
    {
464
        // Check to see if headers have already been sent out, in which case we can't do our job
465
        if(headers_sent($sFilename, $nLineNumber))
466
        {
467
            $sMessage = $this->xTranslator->trans('errors.output.already-sent', [
468
                'location' => $sFilename . ':' . $nLineNumber
469
            ]) . "\n" . $this->xTranslator->trans('errors.output.advice');
470
            throw new RequestException($sMessage);
471
        }
472
473
        $this->di()->getRequestHandler()->processRequest();
474
475
        // Clean the processing buffer
476
        if(($this->xConfigManager->getOption('core.process.clean')))
477
        {
478
            $er = error_reporting(0);
479
            while(ob_get_level() > 0)
480
            {
481
                ob_end_clean();
482
            }
483
            error_reporting($er);
484
        }
485
        if($this->xConfigManager->getOption('core.response.send'))
486
        {
487
            $this->sendResponse();
488
        }
489
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
490
491
    /**
492
     * Prints the response to the output stream, thus sending the response to the browser
493
     *
494
     * @return void
495
     */
496
    public function sendResponse()
497
    {
498
        if(empty($sContent = $this->xResponseManager->getOutput()))
0 ignored issues
show
Coding Style introduced by
Variable assignment found within a condition. Did you mean to do a comparison ?
Loading history...
499
        {
500
            return;
501
        }
502
        if($this->di()->getRequest()->getMethod() === 'GET')
503
        {
504
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
505
            header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
506
            header("Cache-Control: no-cache, must-revalidate");
507
            header("Pragma: no-cache");
508
        }
509
        header('content-type: ' . $this->xResponseManager->getContentType());
510
        print $sContent;
511
        if($this->xConfigManager->getOption('core.process.exit'))
512
        {
513
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
514
        }
515
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
516
517
    /**
518
     * Get a registered response plugin
519
     *
520
     * @param string $sName    The name of the plugin
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
521
     *
522
     * @return ResponsePlugin|null
523
     */
524
    public function plugin(string $sName): ?ResponsePlugin
525
    {
526
        return $this->xPluginManager->getResponsePlugin($sName);
527
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
528
529
    /**
530
     * Get a package instance
531
     *
532
     * @param string $sClassName    The package class name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
533
     *
534
     * @return Package|null
535
     */
536
    public function package(string $sClassName): ?Package
537
    {
538
        return $this->xPackageManager->getPackage($sClassName);
539
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
540
541
    /**
542
     * Get the upload plugin
543
     *
544
     * @return UploadHandler|null
545
     */
546
    public function upload(): ?UploadHandler
547
    {
548
        return $this->di()->getUploadHandler();
549
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
550
551
    /**
552
     * Get the request callback manager
553
     *
554
     * @return CallbackManager
555
     */
556
    public function callback(): CallbackManager
557
    {
558
        return $this->di()->getCallbackManager();
559
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
560
561
    /**
562
     * Get the template engine
563
     *
564
     * @return TemplateEngine
565
     */
566
    public function template(): TemplateEngine
567
    {
568
        return $this->di()->getTemplateEngine();
569
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
570
571
    /**
572
     * Get the App instance
573
     *
574
     * @return App
575
     */
576
    public function app(): App
577
    {
578
        return $this->di()->getApp();
579
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
580
581
    /**
582
     * Get the view renderer
583
     *
584
     * @return ViewRenderer
585
     */
586
    public function view(): ViewRenderer
587
    {
588
        return $this->di()->getViewRenderer();
589
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
590
591
    /**
592
     * Get the paginator
593
     *
594
     * @return Paginator
595
     */
596
    public function paginator(): Paginator
597
    {
598
        return $this->di()->getPaginator();
599
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
600
601
    /**
602
     * Get the Dialog plugin
603
     *
604
     * @return DialogPlugin
605
     */
606
    public function dialog(): DialogPlugin
607
    {
608
        return $this->di()->getDialogPlugin();
609
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
610
611
    /**
612
     * Register a javascript dialog library adapter.
613
     *
614
     * @param string $sClassName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
615
     * @param string $sName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
616
     *
617
     * @return void
618
     * @throws SetupException
619
     */
620
    public function registerDialogLibrary(string $sClassName, string $sName)
621
    {
622
        $this->di()->getDialogLibraryManager()->registerLibrary($sClassName, $sName);
623
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
624
625
    /**
626
     * Get the session manager
627
     *
628
     * @return SessionInterface
629
     */
630
    public function session(): SessionInterface
631
    {
632
        return $this->di()->getSessionManager();
633
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
634
635
    /**
636
     * Reset the library and container instances
637
     *
638
     * @return void
639
     * @throws SetupException
640
     */
641
    public function reset()
642
    {
643
        self::$xInstance = null;
644
        self::$xContainer = null;
645
        // Need to register the default plugins.
646
        self::getInstance()->di()->getPluginManager()->registerPlugins();
647
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
648
}
649