Passed
Push — master ( 888408...eb1365 )
by Thierry
02:11
created

Jaxon::config()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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