Passed
Push — master ( 5b7bca...888408 )
by Thierry
02:13
created

Jaxon::getCharacterEncoding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
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\Config\ConfigManager;
30
use Jaxon\Container\Container;
31
use Jaxon\Exception\RequestException;
32
use Jaxon\Exception\SetupException;
33
use Jaxon\Plugin\Code\CodeGenerator;
34
use Jaxon\Plugin\Package;
35
use Jaxon\Plugin\PluginManager;
36
use Jaxon\Plugin\ResponsePlugin;
37
use Jaxon\Request\Factory\Factory;
38
use Jaxon\Request\Factory\RequestFactory;
39
use Jaxon\Request\Handler\CallbackManager;
40
use Jaxon\Request\Handler\RequestHandler;
41
use Jaxon\Request\Handler\UploadHandler;
42
use Jaxon\Request\Plugin\CallableClass\CallableRegistry;
43
use Jaxon\Response\AbstractResponse;
44
use Jaxon\Response\Response;
45
use Jaxon\Response\ResponseManager;
46
use Jaxon\Session\SessionInterface;
47
use Jaxon\Ui\Dialogs\Dialog;
48
use Jaxon\Ui\View\ViewRenderer;
49
use Jaxon\Utils\Http\UriException;
50
use Jaxon\Utils\Template\Engine as TemplateEngine;
51
use Jaxon\Utils\Translation\Translator;
52
53
use Psr\Log\LoggerAwareInterface;
54
use Psr\Log\LoggerAwareTrait;
55
use Psr\Log\LoggerInterface;
56
use Psr\Log\NullLogger;
57
58
use function headers_sent;
59
60
class Jaxon implements LoggerAwareInterface
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Jaxon
Loading history...
61
{
62
    use LoggerAwareTrait;
63
64
    /**
65
     * Package version number
66
     *
67
     * @const string
68
     */
69
    const VERSION = 'Jaxon 4.0.0-dev';
70
71
    /*
72
     * Request plugins
73
     */
0 ignored issues
show
Coding Style introduced by
Empty line required after block comment
Loading history...
74
    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...
75
    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...
76
    const CALLABLE_FUNCTION = 'CallableFunction';
77
78
    /**
79
     * A static instance on this class
80
     *
81
     * @var Jaxon
82
     */
83
    private static $xInstance = null;
84
85
    /**
86
     * The DI container
87
     *
88
     * @var Container
89
     */
90
    private static $xContainer = null;
91
92
    /**
93
     * @var Translator
94
     */
95
    protected $xTranslator;
96
97
    /**
98
     * @var ConfigManager
99
     */
100
    protected $xConfigManager;
101
102
    /**
103
     * @var PluginManager
104
     */
105
    protected $xPluginManager;
106
107
    /**
108
     * @var CodeGenerator
109
     */
110
    protected $xCodeGenerator;
111
112
    /**
113
     * @var CallableRegistry
114
     */
115
    protected $xClassRegistry;
116
117
    /**
118
     * @var RequestHandler
119
     */
120
    protected $xRequestHandler;
121
122
    /**
123
     * @var ResponseManager
124
     */
125
    protected $xResponseManager;
126
127
    /**
128
     * @return void
129
     */
130
    private static function initInstance()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
131
    {
132
        // Save the Jaxon and container instances in the DI
133
        self::$xContainer->val(Jaxon::class, self::$xInstance);
0 ignored issues
show
Coding Style introduced by
As per coding style, self should be used for accessing local static members.

This check looks for accesses to local static members using the fully qualified name instead of self::.

<?php

class Certificate {
    const TRIPLEDES_CBC = 'ASDFGHJKL';

    private $key;

    public function __construct()
    {
        $this->key = Certificate::TRIPLEDES_CBC;
    }
}

While this is perfectly valid, the fully qualified name of Certificate::TRIPLEDES_CBC could just as well be replaced by self::TRIPLEDES_CBC. Referencing local members with self:: assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.

Loading history...
134
        self::$xContainer->val(Container::class, self::$xContainer);
135
        // Set the attributes from the container
136
        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...
137
        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...
138
        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...
139
        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...
140
        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...
141
        self::$xInstance->xRequestHandler = self::$xContainer->g(RequestHandler::class);
142
        self::$xInstance->xResponseManager = self::$xContainer->g(ResponseManager::class);
143
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
144
145
    /**
146
     * Get the static instance
147
     *
148
     * @return Jaxon
149
     */
150
    public static function getInstance(): ?Jaxon
151
    {
152
        if(self::$xInstance === null)
153
        {
154
            self::$xContainer = new Container(self::getDefaultOptions());
155
            self::$xInstance = new Jaxon();
156
            self::initInstance();
157
        }
158
        return self::$xInstance;
159
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
160
161
    /**
162
     * The constructor
163
     */
164
    private function __construct()
165
    {
166
        // Set the default logger
167
        $this->setLogger(new NullLogger());
168
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
169
170
    /**
171
     * The current Jaxon version
172
     *
173
     * @return string
174
     */
175
    public function getVersion(): string
176
    {
177
        return self::VERSION;
178
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
179
180
    /**
181
     * Get the default options of all components of the library
182
     *
183
     * @return array<string,string|bool|integer>
184
     */
185
    private static function getDefaultOptions(): array
186
    {
187
        // The default configuration settings.
188
        return [
189
            'core.version'                      => self::VERSION,
190
            'core.language'                     => 'en',
191
            'core.encoding'                     => 'utf-8',
192
            'core.decode_utf8'                  => false,
193
            'core.prefix.function'              => 'jaxon_',
194
            'core.prefix.class'                 => 'Jaxon',
195
            // 'core.request.uri'               => '',
196
            'core.request.mode'                 => 'asynchronous',
197
            'core.request.method'               => 'POST', // W3C: Method is case sensitive
198
            'core.response.send'                => true,
199
            'core.response.merge.ap'            => true,
200
            'core.response.merge.js'            => true,
201
            'core.debug.on'                     => false,
202
            'core.debug.verbose'                => false,
203
            'core.process.exit'                 => true,
204
            'core.process.clean'                => false,
205
            'core.process.timeout'              => 6000,
206
            'core.error.handle'                 => false,
207
            'core.error.log_file'               => '',
208
            'core.jquery.no_conflict'           => false,
209
            'core.upload.enabled'               => true,
210
            'js.lib.output_id'                  => 0,
211
            'js.lib.queue_size'                 => 0,
212
            'js.lib.load_timeout'               => 2000,
213
            'js.lib.show_status'                => false,
214
            'js.lib.show_cursor'                => true,
215
            'js.app.dir'                        => '',
216
            'js.app.minify'                     => true,
217
            'js.app.options'                    => '',
218
        ];
219
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
220
221
    /**
222
     * Get the DI container
223
     *
224
     * @return Container
225
     */
226
    public function di(): ?Container
227
    {
228
        return self::$xContainer;
229
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
230
231
    /**
232
     * Get the logger
233
     *
234
     * @return LoggerInterface
235
     */
236
    public function logger(): LoggerInterface
237
    {
238
        return $this->logger;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->logger could return the type null which is incompatible with the type-hinted return Psr\Log\LoggerInterface. Consider adding an additional type-check to rule them out.
Loading history...
239
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
240
241
    /**
242
     * Set the value of a config option
243
     *
244
     * @param string $sName    The option name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
245
     * @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...
246
     *
247
     * @return void
248
     */
249
    public function setOption(string $sName, $sValue)
250
    {
251
        $this->xConfigManager->setOption($sName, $sValue);
252
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
253
254
    /**
255
     * Get the value of a config option
256
     *
257
     * @param string $sName    The option name
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
258
     * @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...
259
     *
260
     * @return mixed        The option value, or null if the option is unknown
261
     */
262
    public function getOption(string $sName, $xDefault = null)
263
    {
264
        return $this->xConfigManager->getOption($sName, $xDefault);
265
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
266
267
    /**
268
     * Check the presence of a config option
269
     *
270
     * @param string $sName    The option name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
271
     *
272
     * @return bool        True if the option exists, and false if not
273
     */
274
    public function hasOption(string $sName): bool
275
    {
276
        return $this->xConfigManager->hasOption($sName);
277
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
278
279
    /**
280
     * Get a translated string
281
     *
282
     * @param string $sText    The key of the translated string
0 ignored issues
show
Coding Style introduced by
Expected 9 spaces after parameter name; 4 found
Loading history...
283
     * @param array $aPlaceHolders    The placeholders of the translated string
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
284
     * @param string $sLanguage    The language of the translated string
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter name; 4 found
Loading history...
285
     *
286
     * @return string
287
     */
288
    public function trans(string $sText, array $aPlaceHolders = [], string $sLanguage = ''): string
289
    {
290
        return $this->xTranslator->trans($sText, $aPlaceHolders, $sLanguage);
291
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
292
293
    /**
294
     * Get the Global Response object
295
     *
296
     * @return AbstractResponse
297
     */
298
    public function getResponse(): AbstractResponse
299
    {
300
        if(($xResponse = $this->xResponseManager->getResponse()))
0 ignored issues
show
Coding Style introduced by
Variable assignment found within a condition. Did you mean to do a comparison ?
Loading history...
301
        {
302
            return $xResponse;
303
        }
304
        return $this->di()->getResponse();
305
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
306
307
    /**
308
     * Create a new Jaxon response object
309
     *
310
     * @return Response
311
     */
312
    public function newResponse(): Response
313
    {
314
        return $this->di()->newResponse();
315
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
316
317
    /**
318
     * Register a plugin
319
     *
320
     * Below is a table for priorities and their description:
321
     * - 0 to 999: Plugins that are part of or extensions to the jaxon core
322
     * - 1000 to 8999: User created plugins, typically, these plugins don't care about order
323
     * - 9000 to 9999: Plugins that generally need to be last or near the end of the plugin list
324
     *
325
     * @param string $sClassName    The plugin class
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
326
     * @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...
327
     * @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...
328
     *
329
     * @return void
330
     * @throws SetupException
331
     */
332
    public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000)
333
    {
334
        $this->xPluginManager->registerPlugin($sClassName, $sPluginName, $nPriority);
335
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
336
337
    /**
338
     * Register a package
339
     *
340
     * @param string $sClassName    The package class
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
341
     * @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...
342
     *
343
     * @return void
344
     * @throws SetupException
345
     */
346
    public function registerPackage(string $sClassName, array $xPkgOptions = [])
347
    {
348
        $this->xPluginManager->registerPackage($sClassName, $xPkgOptions);
349
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
350
351
    /**
352
     * Register request handlers, including functions, callable classes and directories.
353
     *
354
     * @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...
355
     *        Options include:
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 8
Loading history...
356
     *        - 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...
357
     *        - 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...
358
     *        - 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...
359
     * @param string $sName
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
360
     *        When registering a function, this is the name of the function
361
     *        When registering a callable class, this is the class name
362
     *        When registering a callable directory, this is the full path to the directory
363
     * @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...
364
     *
365
     * @return void
366
     * @throws SetupException
367
     */
368
    public function register(string $sType, string $sName, $xOptions = [])
369
    {
370
        $this->xPluginManager->registerCallable($sType, $sName, $xOptions);
371
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
372
373
    /**
374
     * Get an instance of a registered class
375
     *
376
     * @param string $sClassName The class name
377
     *
378
     * @return null|object
379
     * @throws SetupException
380
     */
381
    public function instance(string $sClassName)
382
    {
383
        $xCallable = $this->xClassRegistry->getCallableObject($sClassName);
384
        return ($xCallable) ? $xCallable->getRegisteredObject() : null;
0 ignored issues
show
introduced by
$xCallable is of type Jaxon\Request\Plugin\CallableClass\CallableObject, thus it always evaluated to true.
Loading history...
385
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
386
387
    /**
388
     * Get the factory
389
     *
390
     * @return Factory
391
     */
392
    public function factory(): Factory
393
    {
394
        return $this->di()->g(Factory::class);
395
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
396
397
    /**
398
     * Get a request to a registered class
399
     *
400
     * @param string $sClassName The class name
401
     *
402
     * @return RequestFactory|null
403
     * @throws SetupException
404
     */
405
    public function request(string $sClassName = ''): ?RequestFactory
406
    {
407
        return $this->factory()->request($sClassName);
408
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
409
410
    /**
411
     * Returns the Jaxon Javascript header and wrapper code to be printed into the page
412
     *
413
     * The javascript code returned by this function is dependent on the plugins
414
     * that are included and the functions and classes that are registered.
415
     *
416
     * @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...
417
     * @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...
418
     *
419
     * @return string
420
     * @throws UriException
421
     */
422
    public function getScript(bool $bIncludeJs = false, bool $bIncludeCss = false): string
423
    {
424
        return $this->xCodeGenerator->getScript($bIncludeJs, $bIncludeCss);
425
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
426
427
    /**
428
     * Print the jaxon Javascript header and wrapper code into your page
429
     *
430
     * The javascript code returned by this function is dependent on the plugins
431
     * that are included and the functions and classes that are registered.
432
     *
433
     * @param bool $bIncludeJs    Also print the JS files
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
434
     * @param bool $bIncludeCss    Also print the CSS files
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
435
     *
436
     * @return void
437
     * @throws UriException
438
     */
439
    public function printScript(bool $bIncludeJs = false, bool $bIncludeCss = false)
440
    {
441
        print $this->getScript($bIncludeJs, $bIncludeCss);
442
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
443
444
    /**
445
     * Return the javascript header code and file includes
446
     *
447
     * @return string
448
     */
449
    public function getJs(): string
450
    {
451
        return $this->xCodeGenerator->getJs();
452
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
453
454
    /**
455
     * Return the CSS header code and file includes
456
     *
457
     * @return string
458
     */
459
    public function getCss(): string
460
    {
461
        return $this->xCodeGenerator->getCss();
462
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
463
464
    /**
465
     * Determine if a call is a jaxon request or a page load request
466
     *
467
     * @return bool
468
     */
469
    public function canProcessRequest(): bool
470
    {
471
        return $this->xRequestHandler->canProcessRequest();
472
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
473
474
    /**
475
     * If this is a jaxon request, call the requested PHP function, build the response and send it back to the browser
476
     *
477
     * This is the main server side engine for Jaxon.
478
     * It handles all the incoming requests, including the firing of events and handling of the response.
479
     * If your RequestURI is the same as your web page, then this function should be called before ANY
480
     * headers or HTML is output from your script.
481
     *
482
     * This function may exit after the request is processed, if the 'core.process.exit' option is set to true.
483
     *
484
     * @return void
485
     *
486
     * @throws RequestException
487
     * @see <Jaxon\Jaxon->canProcessRequest>
488
     */
489
    public function processRequest()
490
    {
491
        // Check to see if headers have already been sent out, in which case we can't do our job
492
        if(headers_sent($sFilename, $nLineNumber))
493
        {
494
            echo $this->xTranslator->trans('errors.output.already-sent', [
495
                'location' => $sFilename . ':' . $nLineNumber
496
            ]), "\n", $this->xTranslator->trans('errors.output.advice');
497
            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...
498
        }
499
500
        $this->xRequestHandler->processRequest();
501
502
        if(($this->xConfigManager->getOption('core.response.send')))
503
        {
504
            $this->xResponseManager->sendOutput();
505
            if(($this->xConfigManager->getOption('core.process.exit')))
506
            {
507
                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...
508
            }
509
        }
510
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
511
512
    /**
513
     * Get a registered response plugin
514
     *
515
     * @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...
516
     *
517
     * @return ResponsePlugin|null
518
     */
519
    public function plugin(string $sName): ?ResponsePlugin
520
    {
521
        return $this->xPluginManager->getResponsePlugin($sName);
522
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
523
524
    /**
525
     * Get a package instance
526
     *
527
     * @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...
528
     *
529
     * @return Package|null
530
     */
531
    public function package(string $sClassName): ?Package
532
    {
533
        return $this->xPluginManager->getPackage($sClassName);
534
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
535
536
    /**
537
     * Get the upload plugin
538
     *
539
     * @return UploadHandler|null
540
     */
541
    public function upload(): ?UploadHandler
542
    {
543
        return $this->di()->getUploadHandler();
544
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
545
546
    /**
547
     * Get the request callback manager
548
     *
549
     * @return CallbackManager
550
     */
551
    public function callback(): CallbackManager
552
    {
553
        return $this->xRequestHandler->getCallbackManager();
554
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
555
556
    /**
557
     * Get the dialog wrapper
558
     *
559
     * @return Dialog
560
     */
561
    public function dialog(): Dialog
562
    {
563
        return $this->di()->getDialog();
564
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
565
566
    /**
567
     * Get the template engine
568
     *
569
     * @return TemplateEngine
570
     */
571
    public function template(): TemplateEngine
572
    {
573
        return $this->di()->getTemplateEngine();
574
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
575
576
    /**
577
     * Get the App instance
578
     *
579
     * @return App
580
     */
581
    public function app(): App
582
    {
583
        return $this->di()->getApp();
584
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
585
586
    /**
587
     * Get the view renderer
588
     *
589
     * @return ViewRenderer
590
     */
591
    public function view(): ViewRenderer
592
    {
593
        return $this->di()->getViewRenderer();
594
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
595
596
    /**
597
     * Get the session manager
598
     *
599
     * @return SessionInterface
600
     */
601
    public function session(): SessionInterface
602
    {
603
        return $this->di()->getSessionManager();
604
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
605
}
606