Passed
Push — master ( 37d9b5...bf2aee )
by Thierry
04:39 queued 02:29
created

PluginManager::getPackageOptions()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
nc 5
nop 1
dl 0
loc 19
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * ResponseManager.php - Jaxon plugin manager
5
 *
6
 * Register Jaxon plugins, generate corresponding code, handle request
7
 * and redirect them to the right plugin.
8
 *
9
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
10
 * @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...
11
 * @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...
12
 * @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...
13
 * @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...
14
 * @author Thierry Feuzeu <[email protected]>
15
 * @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...
16
 * @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...
17
 * @copyright 2016 Thierry Feuzeu <[email protected]>
18
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
19
 * @link https://github.com/jaxon-php/jaxon-core
20
 */
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...
21
22
namespace Jaxon\Plugin\Manager;
23
24
use Jaxon\Jaxon;
25
use Jaxon\Config\ConfigManager;
26
use Jaxon\Container\Container;
27
use Jaxon\Exception\SetupException;
28
use Jaxon\Plugin\Code\CodeGenerator;
29
use Jaxon\Plugin\Contract\CallableRegistryInterface;
30
use Jaxon\Plugin\Contract\CodeGeneratorInterface;
31
use Jaxon\Plugin\Contract\RequestHandlerInterface;
32
use Jaxon\Plugin\Contract\ResponsePluginInterface;
33
use Jaxon\Plugin\Package;
34
use Jaxon\Plugin\RequestPlugin;
35
use Jaxon\Plugin\ResponsePlugin;
36
use Jaxon\Request\Plugin\CallableClass\CallableClassPlugin;
37
use Jaxon\Request\Plugin\CallableClass\CallableDirPlugin;
38
use Jaxon\Request\Plugin\CallableFunction\CallableFunctionPlugin;
39
use Jaxon\Response\Plugin\DataBag\DataBagPlugin;
40
use Jaxon\Response\Plugin\JQuery\JQueryPlugin;
41
use Jaxon\Response\Response;
42
use Jaxon\Ui\Dialogs\MessageInterface;
43
use Jaxon\Ui\Dialogs\QuestionInterface;
44
use Jaxon\Ui\View\ViewManager;
45
use Jaxon\Utils\Config\Config;
46
use Jaxon\Utils\Translation\Translator;
47
48
use Closure;
49
50
use function class_implements;
51
use function in_array;
52
use function is_array;
53
use function is_integer;
54
use function is_string;
55
use function is_subclass_of;
56
use function trim;
57
58
class PluginManager
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class PluginManager
Loading history...
59
{
60
    /**
61
     * @var Container
62
     */
63
    protected $di;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
64
65
    /**
66
     * @var Translator
67
     */
68
    protected $xTranslator;
69
70
    /**
71
     * @var ConfigManager
72
     */
73
    protected $xConfigManager;
74
75
    /**
76
     * @var ViewManager
77
     */
78
    protected $xViewManager;
79
80
    /**
81
     * The code generator
82
     *
83
     * @var CodeGenerator
84
     */
85
    private $xCodeGenerator;
86
87
    /**
88
     * Request plugins, indexed by name
89
     *
90
     * @var array<CallableRegistryInterface>
91
     */
92
    private $aRegistryPlugins = [];
93
94
    /**
95
     * Request handlers, indexed by name
96
     *
97
     * @var array<RequestHandlerInterface>
98
     */
99
    private $aRequestHandlers = [];
100
101
    /**
102
     * Response plugins, indexed by name
103
     *
104
     * @var array<ResponsePluginInterface>
105
     */
106
    private $aResponsePlugins = [];
107
108
    /**
109
     * The constructor
110
     *
111
     * @param Container $di
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
112
     * @param ConfigManager $xConfigManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
113
     * @param ViewManager $xViewManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
114
     * @param CodeGenerator $xCodeGenerator
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
115
     * @param Translator $xTranslator
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
116
     */
117
    public function __construct(Container $di, ConfigManager $xConfigManager,
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
118
        ViewManager $xViewManager, CodeGenerator $xCodeGenerator, Translator $xTranslator)
119
    {
120
        $this->di = $di;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 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...
121
        $this->xConfigManager = $xConfigManager;
122
        $this->xViewManager = $xViewManager;
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...
123
        $this->xCodeGenerator = $xCodeGenerator;
124
        $this->xTranslator = $xTranslator;
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...
125
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
126
127
    /**
128
     * Get the request plugins
129
     *
130
     * @return array<RequestPlugin>
131
     */
132
    public function getRequestHandlers(): array
133
    {
134
        return $this->aRequestHandlers;
135
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
136
137
    /**
138
     * Get a package instance
139
     *
140
     * @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...
141
     *
142
     * @return Package|null
143
     */
144
    public function getPackage(string $sClassName): ?Package
145
    {
146
        return $this->di->get(trim($sClassName, '\\ '));
147
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
148
149
    /**
150
     * Register a plugin
151
     *
152
     * Below is a table for priorities and their description:
153
     * - 0 to 999: Plugins that are part of or extensions to the jaxon core
154
     * - 1000 to 8999: User created plugins, typically, these plugins don't care about order
155
     * - 9000 to 9999: Plugins that generally need to be last or near the end of the plugin list
156
     *
157
     * @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...
158
     * @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...
159
     * @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...
160
     *
161
     * @return void
162
     * @throws SetupException
163
     */
164
    public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000)
165
    {
166
        $bIsUsed = false;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
167
        $aInterfaces = class_implements($sClassName);
168
        if(in_array(CodeGeneratorInterface::class, $aInterfaces))
169
        {
170
            $this->xCodeGenerator->addGenerator($sClassName, $nPriority);
171
            $bIsUsed = true;
172
        }
173
        if(in_array(CallableRegistryInterface::class, $aInterfaces))
174
        {
175
            $this->aRegistryPlugins[$sPluginName] = $sClassName;
176
            $bIsUsed = true;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 30 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...
177
        }
178
        if(in_array(RequestHandlerInterface::class, $aInterfaces))
179
        {
180
            $this->aRequestHandlers[$sPluginName] = $sClassName;
181
            $bIsUsed = true;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 30 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...
182
        }
183
        if(in_array(ResponsePluginInterface::class, $aInterfaces))
184
        {
185
            $this->aResponsePlugins[$sPluginName] = $sClassName;
186
            $bIsUsed = true;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 30 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...
187
        }
188
189
        // This plugin implements the Message interface
190
        if(in_array(MessageInterface::class, $aInterfaces))
191
        {
192
            $this->di->getDialog()->setMessage($sClassName);
193
            $bIsUsed = true;
194
        }
195
        // This plugin implements the Question interface
196
        if(in_array(QuestionInterface::class, $aInterfaces))
197
        {
198
            $this->di->getDialog()->setQuestion($sClassName);
199
            $bIsUsed = true;
200
        }
201
202
        if(!$bIsUsed)
203
        {
204
            // The class is invalid.
205
            $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
206
            throw new SetupException($sMessage);
207
        }
208
209
        // Register the plugin in the DI container, if necessary
210
        if(!$this->di->has($sClassName))
211
        {
212
            $this->di->auto($sClassName);
213
        }
214
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
215
216
    /**
217
     * Register a function or callable class
218
     *
219
     * Call the request plugin with the $sType defined as name.
220
     *
221
     * @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...
Coding Style introduced by
Expected 5 spaces after parameter name; 4 found
Loading history...
222
     * @param string $sCallable    The callable entity being registered
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
223
     * @param array|string $xOptions    The associated options
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
224
     *
225
     * @return void
226
     * @throws SetupException
227
     */
228
    public function registerCallable(string $sType, string $sCallable, $xOptions = [])
229
    {
230
        if(isset($this->aRegistryPlugins[$sType]) &&
231
            ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType])))
0 ignored issues
show
Bug introduced by
$this->aRegistryPlugins[$sType] of type Jaxon\Plugin\Contract\CallableRegistryInterface is incompatible with the type string expected by parameter $sClass of Jaxon\Container\Container::g(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

231
            ($xPlugin = $this->di->g(/** @scrutinizer ignore-type */ $this->aRegistryPlugins[$sType])))
Loading history...
Coding Style introduced by
Variable assignment found within a condition. Did you mean to do a comparison ?
Loading history...
232
        {
233
            $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions));
234
            return;
235
        }
236
        throw new SetupException($this->xTranslator->trans('errors.register.plugin',
237
            ['name' => $sType, 'callable' => $sCallable]));
238
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
239
240
    /**
241
     * Register callables from a section of the config
242
     *
243
     * @param array $aOptions    The content of the config section
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter name; 4 found
Loading history...
244
     * @param string $sCallableType    The type of callable to register
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
245
     *
246
     * @return void
247
     * @throws SetupException
248
     */
249
    private function registerCallablesFromOptions(array $aOptions, string $sCallableType)
250
    {
251
        foreach($aOptions as $xKey => $xValue)
252
        {
253
            if(is_integer($xKey) && is_string($xValue))
254
            {
255
                // Register a function without options
256
                $this->registerCallable($sCallableType, $xValue);
257
            }
258
            elseif(is_string($xKey) && (is_array($xValue) || is_string($xValue)))
259
            {
260
                // Register a function with options
261
                $this->registerCallable($sCallableType, $xKey, $xValue);
262
            }
263
        }
264
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
265
266
    /**
267
     * Save items in the DI container
268
     *
269
     * @param Config $xConfig
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
270
     *
271
     * @return void
272
     */
273
    private function updateContainer(Config $xConfig)
274
    {
275
        $aOptions = $xConfig->getOption('container', []);
276
        foreach($aOptions as $xKey => $xValue)
277
        {
278
            if(is_integer($xKey) && is_string($xValue))
279
            {
280
                // The value of the entry is the class name
281
                $this->di->auto($xValue);
282
            }
283
            elseif($xValue instanceof Closure)
284
            {
285
                // The key is the class name. It must be a string.
286
                $this->di->set((string)$xKey, $xValue);
287
            }
288
            else
289
            {
290
                // The key is the class name. It must be a string.
291
                $this->di->val((string)$xKey, $xValue);
292
            }
293
        }
294
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
295
296
    /**
297
     * Read and set Jaxon options from a JSON config file
298
     *
299
     * @param Config $xConfig The config options
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
300
     * @param Config|null $xPkgConfig The user provided package options
301
     *
302
     * @return void
303
     * @throws SetupException
304
     */
305
    private function registerItemsFromConfig(Config $xConfig, ?Config $xPkgConfig = null)
306
    {
307
        $aSections = [
308
            'functions' => Jaxon::CALLABLE_FUNCTION,
309
            'classes' => Jaxon::CALLABLE_CLASS,
310
            'directories' => Jaxon::CALLABLE_DIR,
311
        ];
312
        // Register functions, classes and directories
313
        foreach($aSections as $sSection => $sCallableType)
314
        {
315
            $this->registerCallablesFromOptions($xConfig->getOption($sSection, []), $sCallableType);
316
        }
317
        // Register the view namespaces
318
        // Note: the $xPkgConfig can provide a "template" option, which is used to customize
319
        // the user defined view namespaces. That's why it is needed here.
320
        $this->xViewManager->addNamespaces($xConfig, $xPkgConfig);
321
        // Save items in the DI container
322
        $this->updateContainer($xConfig);
323
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
324
325
    /**
326
     * Get package options
327
     *
328
     * @param string $sClassName    The package class
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
329
     *
330
     * @return array
331
     * @throws SetupException
332
     */
333
    private function getPackageOptions(string $sClassName): array
334
    {
335
        if(!is_subclass_of($sClassName, Package::class))
336
        {
337
            $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
338
            throw new SetupException($sMessage);
339
        }
340
        // $this->aPackages contains packages config file paths.
341
        $aLibOptions = $sClassName::config();
342
        if(is_string($aLibOptions))
343
        {
344
            $aLibOptions = $this->xConfigManager->read($aLibOptions);
345
        }
346
        if(!is_array($aLibOptions))
347
        {
348
            $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
349
            throw new SetupException($sMessage);
350
        }
351
        return $aLibOptions;
352
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
353
354
    /**
355
     * Register a package
356
     *
357
     * @param string $sClassName    The package class
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
358
     * @param array $aPkgOptions    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...
359
     *
360
     * @return void
361
     * @throws SetupException
362
     */
363
    public function registerPackage(string $sClassName, array $aPkgOptions)
364
    {
365
        $sClassName = trim($sClassName, '\\ ');
366
        $aLibOptions = $this->getPackageOptions($sClassName);
367
        // Add the package name to the config
368
        $aLibOptions['package'] = $sClassName;
369
        $xLibConfig = $this->xConfigManager->newConfig($aLibOptions);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 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...
370
        $xPkgConfig = $this->xConfigManager->newConfig($aPkgOptions);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 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...
371
        $this->di->registerPackage($sClassName, $xPkgConfig);
372
        // Register the declarations in the package config.
373
        $this->registerItemsFromConfig($xLibConfig, $xPkgConfig);
374
        // Register the package as a code generator.
375
        $this->xCodeGenerator->addGenerator($sClassName, 500);
376
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
377
378
    /**
379
     * Read and set Jaxon options from a JSON config file
380
     *
381
     * @param Config $xAppConfig    The config options
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
382
     *
383
     * @return void
384
     * @throws SetupException
385
     */
386
    public function registerFromConfig(Config $xAppConfig)
387
    {
388
        $this->registerItemsFromConfig($xAppConfig);
389
390
        // Register packages
391
        $aPackageConfig = $xAppConfig->getOption('packages', []);
392
        foreach($aPackageConfig as $sClassName => $aPkgOptions)
393
        {
394
            $this->registerPackage($sClassName, $aPkgOptions);
395
        }
396
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
397
398
    /**
399
     * Find the specified response plugin by name and return a reference to it if one exists
400
     *
401
     * @param string $sName    The name of the plugin
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 4 found
Loading history...
402
     * @param Response|null $xResponse    The response to attach the plugin to
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
403
     *
404
     * @return ResponsePlugin|null
405
     */
406
    public function getResponsePlugin(string $sName, ?Response $xResponse = null): ?ResponsePlugin
407
    {
408
        if(!isset($this->aResponsePlugins[$sName]))
409
        {
410
            return null;
411
        }
412
        $xPlugin = $this->di->g($this->aResponsePlugins[$sName]);
0 ignored issues
show
Bug introduced by
$this->aResponsePlugins[$sName] of type Jaxon\Plugin\Contract\ResponsePluginInterface is incompatible with the type string expected by parameter $sClass of Jaxon\Container\Container::g(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

412
        $xPlugin = $this->di->g(/** @scrutinizer ignore-type */ $this->aResponsePlugins[$sName]);
Loading history...
413
        if(($xResponse))
414
        {
415
            $xPlugin->setResponse($xResponse);
416
        }
417
        return $xPlugin;
418
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
419
420
    /**
421
     * Register the Jaxon request plugins
422
     *
423
     * @return void
424
     * @throws SetupException
425
     */
426
    public function registerPlugins()
427
    {
428
        // Request plugins
429
        $this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101);
430
        $this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102);
431
        $this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103);
432
433
        // Register the JQuery response plugin
434
        $this->registerPlugin(JQueryPlugin::class, JQueryPlugin::NAME, 700);
435
        // Register the DataBag response plugin
436
        $this->registerPlugin(DataBagPlugin::class, DataBagPlugin::NAME, 700);
437
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
438
}
439