Passed
Push — master ( dc0218...f79a4b )
by Thierry
02:43
created

Bootstrap::run()   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
 * Boot.php - Jaxon application bootstrapper
5
 *
6
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2019 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-core
11
 */
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...
12
13
namespace Jaxon\App;
14
15
use Jaxon\Jaxon;
16
use Jaxon\Plugin\Manager as PluginManager;
17
use Jaxon\Request\Handler\Handler as RequestHandler;
18
use Jaxon\Ui\View\Manager as ViewManager;
19
use Jaxon\Utils\Config\Config;
20
use Jaxon\Utils\Translation\Translator;
21
use Jaxon\Exception\SetupException;
22
use Jaxon\Utils\Config\Exception\DataDepth;
23
24
class Bootstrap
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Bootstrap
Loading history...
25
{
26
    /**
27
     * @var Jaxon
28
     */
29
    private $jaxon;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
30
31
    /**
32
     * @var PluginManager
33
     */
34
    private $xPluginManager;
35
36
    /**
37
     * @var ViewManager
38
     */
39
    private $xViewManager;
40
41
    /**
42
     * @var RequestHandler
43
     */
44
    private $xRequestHandler;
45
46
    /**
47
     * @var Translator
48
     */
49
    private $xTranslator;
50
51
    /**
52
     * The library options
53
     *
54
     * @var array
55
     */
56
    private $aLibOptions = [];
57
58
    /**
59
     * The application options
60
     *
61
     * @var array
62
     */
63
    private $aAppOptions = [];
64
65
    /**
66
     * The Ajax endpoint URI
67
     *
68
     * @var string
69
     */
70
    private $sUri = '';
71
72
    /**
73
     * The js code URI
74
     *
75
     * @var string
76
     */
77
    private $sJsUri = '';
78
79
    /**
80
     * The js code dir
81
     *
82
     * @var string
83
     */
84
    private $sJsDir = '';
85
86
    /**
87
     * Export the js code
88
     *
89
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
90
     */
91
    private $bExportJs = false;
92
93
    /**
94
     * Minify the js code
95
     *
96
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
97
     */
98
    private $bMinifyJs = false;
99
100
    /**
101
     * The class constructor
102
     *
103
     * @param Jaxon $jaxon
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
104
     * @param PluginManager $xPluginManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
105
     * @param ViewManager $xViewManager
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...
106
     * @param RequestHandler $xRequestHandler
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
107
     * @param Translator $xTranslator
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...
108
     */
109
    public function __construct(Jaxon $jaxon, PluginManager $xPluginManager,
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
110
        ViewManager $xViewManager, RequestHandler $xRequestHandler, Translator $xTranslator)
111
    {
112
        $this->jaxon = $jaxon;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
113
        $this->xPluginManager = $xPluginManager;
114
        $this->xViewManager = $xViewManager;
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...
115
        $this->xRequestHandler = $xRequestHandler;
116
        $this->xTranslator = $xTranslator;
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...
117
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
118
119
    /**
120
     * Set the library options
121
     *
122
     * @param array $aLibOptions    The library options
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
123
     *
124
     * @return Bootstrap
125
     */
126
    public function lib(array $aLibOptions): Bootstrap
127
    {
128
        $this->aLibOptions = $aLibOptions;
129
        return $this;
130
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
131
132
    /**
133
     * Set the applications options
134
     *
135
     * @param array $aAppOptions    The application options
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
136
     *
137
     * @return Bootstrap
138
     */
139
    public function app(array $aAppOptions): Bootstrap
140
    {
141
        $this->aAppOptions = $aAppOptions;
142
        return $this;
143
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
144
145
    /**
146
     * Set the ajax endpoint URI
147
     *
148
     * @param string $sUri    The ajax endpoint URI
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
149
     *
150
     * @return Bootstrap
151
     */
152
    public function uri(string $sUri): Bootstrap
153
    {
154
        $this->sUri = $sUri;
155
        return $this;
156
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
157
158
    /**
159
     * Set the javascript code
160
     *
161
     * @param bool $bExportJs    Whether to export the js code in a file
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
162
     * @param string $sJsUri    The URI to access the js file
163
     * @param string $sJsDir    The directory where to create the js file
164
     * @param bool $bMinifyJs    Whether to minify the exported js file
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
165
     *
166
     * @return Bootstrap
167
     */
168
    public function js(bool $bExportJs, string $sJsUri = '', string $sJsDir = '', bool $bMinifyJs = false): Bootstrap
169
    {
170
        $this->sJsUri = $sJsUri;
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...
171
        $this->sJsDir = $sJsDir;
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...
172
        $this->bExportJs = $bExportJs;
173
        $this->bMinifyJs = $bMinifyJs;
174
        return $this;
175
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
176
177
    /**
178
     * Set the Jaxon application options.
179
     *
180
     * @param Config $xAppConfig    The config options
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
181
     *
182
     * @return void
183
     * @throws SetupException
184
     */
185
    private function setupApp(Config $xAppConfig)
186
    {
187
        // Register user functions and classes
188
        $this->xPluginManager->registerFromConfig($xAppConfig);
189
        // Save the view namespaces
190
        $this->xViewManager->addNamespaces($xAppConfig);
191
        // Call the on boot callbacks
192
        $this->xRequestHandler->onBoot();
193
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
194
195
    /**
196
     * Wraps the module/package/bundle setup method.
197
     *
198
     * @return void
199
     * @throws SetupException
200
     */
201
    public function setup()
202
    {
203
        $di = $this->jaxon->di();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
204
        $xLibConfig = $di->getConfig();
205
206
        // Setup the lib config options.
207
        try
208
        {
209
            $xLibConfig->setOptions($this->aLibOptions);
210
        }
211
        catch(DataDepth $e)
212
        {
213
            $sMessage = $this->xTranslator->trans('errors.data.depth', ['key' => $e->sPrefix, 'depth' => $e->nDepth]);
214
            throw new SetupException($sMessage);
215
        }
216
217
        // Get the app config options.
218
        $xAppConfig = $di->newConfig($this->aAppOptions);
219
        $xAppConfig->setOption('options.views.default', 'default');
220
        // Setup the app.
221
        $this->setupApp($xAppConfig);
222
223
        // Jaxon library settings
224
        if(!$xLibConfig->hasOption('js.app.export'))
225
        {
226
            $xLibConfig->setOption('js.app.export', $this->bExportJs);
227
        }
228
        if(!$xLibConfig->hasOption('js.app.minify'))
229
        {
230
            $xLibConfig->setOption('js.app.minify', $this->bMinifyJs);
231
        }
232
        if(!$xLibConfig->hasOption('js.app.uri') && $this->sJsUri != '')
233
        {
234
            $xLibConfig->setOption('js.app.uri', $this->sJsUri);
235
        }
236
        if(!$xLibConfig->hasOption('js.app.dir') && $this->sJsDir != '')
237
        {
238
            $xLibConfig->setOption('js.app.dir', $this->sJsDir);
239
        }
240
        // Set the request URI
241
        if(!$xLibConfig->hasOption('core.request.uri') && $this->sUri != '')
242
        {
243
            $xLibConfig->setOption('core.request.uri', $this->sUri);
244
        }
245
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
246
}
247