Issues (2884)

src/App/Bootstrap.php (29 issues)

1
<?php
2
3
/**
4
 * Bootstrap.php
5
 *
6
 * Jaxon application bootstrapper
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2019 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
0 ignored issues
show
PHP version not specified
Loading history...
Missing @category tag in file comment
Loading history...
14
15
namespace Jaxon\App;
16
17
use Jaxon\App\Config\ConfigManager;
18
use Jaxon\App\View\ViewRenderer;
19
use Jaxon\Exception\SetupException;
20
use Jaxon\Plugin\Manager\PackageManager;
21
use Jaxon\Request\Handler\CallbackManager;
22
use Jaxon\Utils\Config\Config;
23
24
use function call_user_func;
25
26
class Bootstrap
0 ignored issues
show
Missing doc comment for class Bootstrap
Loading history...
27
{
28
    /**
29
     * @var ConfigManager
30
     */
31
    private $xConfigManager;
0 ignored issues
show
Expected 1 blank line(s) before first member var; 0 found
Loading history...
32
33
    /**
34
     * @var PackageManager
35
     */
36
    private $xPackageManager;
37
38
    /**
39
     * @var CallbackManager
40
     */
41
    private $xCallbackManager;
42
43
    /**
44
     * @var ViewRenderer
45
     */
46
    private $xViewRenderer;
47
48
    /**
49
     * The library options
50
     *
51
     * @var array
52
     */
53
    private $aLibOptions = [];
54
55
    /**
56
     * The application options
57
     *
58
     * @var array
59
     */
60
    private $aAppOptions = [];
61
62
    /**
63
     * The class constructor
64
     *
65
     * @param ConfigManager $xConfigManager
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 3 spaces after parameter type; 1 found
Loading history...
66
     * @param PackageManager $xPackageManager
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 2 spaces after parameter type; 1 found
Loading history...
67
     * @param CallbackManager $xCallbackManager
0 ignored issues
show
Missing parameter comment
Loading history...
68
     * @param ViewRenderer $xViewRenderer
0 ignored issues
show
Missing parameter comment
Loading history...
Expected 4 spaces after parameter type; 1 found
Loading history...
69
     */
70
    public function __construct(ConfigManager $xConfigManager, PackageManager $xPackageManager,
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
71
        CallbackManager $xCallbackManager, ViewRenderer $xViewRenderer)
72
    {
73
        $this->xConfigManager = $xConfigManager;
0 ignored issues
show
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...
74
        $this->xPackageManager = $xPackageManager;
75
        $this->xCallbackManager = $xCallbackManager;
76
        $this->xViewRenderer = $xViewRenderer;
0 ignored issues
show
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...
77
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
78
79
    /**
80
     * Set the library options
81
     *
82
     * @param array $aLibOptions    The library options
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
83
     *
84
     * @return Bootstrap
85
     */
86
    public function lib(array $aLibOptions): Bootstrap
87
    {
88
        $this->aLibOptions = $aLibOptions;
89
        return $this;
90
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
91
92
    /**
93
     * Set the applications options
94
     *
95
     * @param array $aAppOptions    The application options
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
96
     *
97
     * @return Bootstrap
98
     */
99
    public function app(array $aAppOptions): Bootstrap
100
    {
101
        $this->aAppOptions = $aAppOptions;
102
        return $this;
103
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
104
105
    /**
106
     * Set the javascript asset
107
     *
108
     * @param bool $bExport    Whether to export the js code in a file
0 ignored issues
show
Expected 3 spaces after parameter type; 1 found
Loading history...
Expected 1 spaces after parameter name; 4 found
Loading history...
109
     * @param bool $bMinify    Whether to minify the exported js file
0 ignored issues
show
Expected 3 spaces after parameter type; 1 found
Loading history...
Expected 1 spaces after parameter name; 4 found
Loading history...
110
     * @param string $sUri    The URI to access the js file
111
     * @param string $sDir    The directory where to create the js file
112
     *
113
     * @return Bootstrap
114
     */
115
    public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): Bootstrap
116
    {
117
        // Jaxon library settings
118
        $this->xConfigManager->setOption('js.app.export', $bExport);
119
        $this->xConfigManager->setOption('js.app.minify', $bMinify);
120
        if($sUri !== '')
121
        {
122
            $this->xConfigManager->setOption('js.app.uri', $sUri);
123
        }
124
        if($sDir !== '')
125
        {
126
            $this->xConfigManager->setOption('js.app.dir', $sDir);
127
        }
128
        return $this;
129
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
130
131
    /**
132
     * Set the Jaxon application options.
133
     *
134
     * @param Config $xAppConfig    The config options
0 ignored issues
show
Expected 1 spaces after parameter name; 4 found
Loading history...
135
     *
136
     * @return void
137
     * @throws SetupException
138
     */
139
    private function setupApp(Config $xAppConfig)
140
    {
141
        // Register user functions and classes
142
        $this->xPackageManager->registerFromConfig($xAppConfig);
143
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
144
145
    /**
146
     * Wraps the module/package/bundle setup method.
147
     *
148
     * @return void
149
     * @throws SetupException
150
     */
151
    public function setup()
152
    {
153
        // Prevent the Jaxon library from sending the response or exiting
154
        $this->xConfigManager->setOption('core.response.send', false);
155
        $this->xConfigManager->setOption('core.process.exit', false);
156
157
        // Setup the lib config options.
158
        $this->xConfigManager->setOptions($this->aLibOptions);
159
        // Get the app config options.
160
        $xAppConfig = $this->xConfigManager->newConfig($this->aAppOptions);
161
162
        // Setup the app.
163
        $this->setupApp($xAppConfig);
164
        $this->onBoot();
165
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
166
167
    /**
168
     * These callbacks are called right after the library is initialized.
169
     *
170
     * @return void
171
     */
172
    public function onBoot()
173
    {
174
        // Only call the callbacks that aren't called yet.
175
        $aBootCallbacks = $this->xCallbackManager->popBootCallbacks();
176
        foreach($aBootCallbacks as $aBootCallback)
177
        {
178
            call_user_func($aBootCallback);
179
        }
180
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
181
}
182