Passed
Push — master ( 68b778...1b1614 )
by Thierry
07:15 queued 04:29
created

Bootstrap::run()   B

Complexity

Conditions 9
Paths 32

Size

Total Lines 50
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 50
rs 8.0555
cc 9
nc 32
nop 0
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\Utils\Config\Config;
16
17
class Bootstrap
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Bootstrap
Loading history...
18
{
19
    use \Jaxon\Features\Event;
20
21
    /**
22
     * The library options
23
     *
24
     * @var array
25
     */
26
    private $aLibOptions = [];
27
28
    /**
29
     * The application options
30
     *
31
     * @var array
32
     */
33
    private $aAppOptions = [];
34
35
    /**
36
     * The Ajax endpoint URI
37
     *
38
     * @var string
39
     */
40
    private $sUri = '';
41
42
    /**
43
     * The js code URI
44
     *
45
     * @var string
46
     */
47
    private $sJsUri = '';
48
49
    /**
50
     * The js code dir
51
     *
52
     * @var string
53
     */
54
    private $sJsDir = '';
55
56
    /**
57
     * Export the js code
58
     *
59
     * @var boolean
60
     */
61
    private $bExportJs = false;
62
63
    /**
64
     * Minify the js code
65
     *
66
     * @var boolean
67
     */
68
    private $bMinifyJs = false;
69
70
    /**
71
     * Set the library options
72
     *
73
     * @param array       $aLibOptions    The library options
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
74
     *
75
     * @return Bootstrap
76
     */
77
    public function lib(array $aLibOptions)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
78
    {
79
        $this->aLibOptions = $aLibOptions;
80
        return $this;
81
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
82
83
    /**
84
     * Set the applications options
85
     *
86
     * @param array       $aAppOptions    The application options
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
87
     *
88
     * @return Bootstrap
89
     */
90
    public function app(array $aAppOptions)
91
    {
92
        $this->aAppOptions = $aAppOptions;
93
        return $this;
94
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
95
96
    /**
97
     * Set the ajax endpoint URI
98
     *
99
     * @param string  $sUri   The ajax endpoint URI
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 3 found
Loading history...
100
     *
101
     * @return Bootstrap
102
     */
103
    public function uri($sUri)
104
    {
105
        $this->sUri = $sUri;
106
        return $this;
107
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
108
109
    /**
110
     * Set the javascript code
111
     *
112
     * @param boolean   $bExportJs      Whether to export the js code in a file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 6 found
Loading history...
113
     * @param string    $sJsUri         The URI to access the js file
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 4 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 9 found
Loading history...
114
     * @param string    $sJsDir         The directory where to create the js file
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 4 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 9 found
Loading history...
115
     * @param boolean   $bMinifyJs      Whether to minify the exported js file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 3 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 6 found
Loading history...
116
     *
117
     * @return Bootstrap
118
     */
119
    public function js($bExportJs, $sJsUri = '', $sJsDir = '', $bMinifyJs = false)
120
    {
121
        $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...
122
        $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...
123
        $this->bExportJs = $bExportJs;
124
        $this->bMinifyJs = $bMinifyJs;
125
        return $this;
126
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
127
128
    /**
129
     * Set the Jaxon application options.
130
     *
131
     * @param Config        $xAppConfig        The config options
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 8 found
Loading history...
132
     *
133
     * @return void
134
     */
135
    private function setupApp($xAppConfig)
136
    {
137
        $di = jaxon()->di();
138
        // Register user functions and classes
139
        $di->getPluginManager()->registerFromConfig($xAppConfig);
140
        // Save the view namespaces
141
        $di->getViewManager()->addNamespaces($xAppConfig);
142
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
143
144
    /**
145
     * Wraps the module/package/bundle setup method.
146
     *
147
     * @return void
148
     */
149
    public function run()
150
    {
151
        $jaxon = jaxon();
152
        $di = $jaxon->di();
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...
153
154
        // Event before setting up the module
155
        $this->triggerEvent('pre.setup');
156
157
        // Setup the lib config options.
158
        $di->getConfig()->setOptions($this->aLibOptions);
159
160
        // Event before the module has set the config
161
        $this->triggerEvent('pre.config');
162
163
        // Get the app config options.
164
        $xAppConfig = $di->newConfig($this->aAppOptions);
165
        $xAppConfig->setOption('options.views.default', 'default');
166
        // Setup the app.
167
        $this->setupApp($xAppConfig);
168
169
        // Event after the module has read the config
170
        $this->triggerEvent('post.config');
171
172
        // Use the Composer autoloader. It's important to call this before triggers and callbacks.
173
        // $jaxon->useComposerAutoloader();
174
        // Jaxon library settings
175
        if(!$jaxon->hasOption('js.app.export'))
176
        {
177
            $jaxon->setOption('js.app.export', $this->bExportJs);
178
        }
179
        if(!$jaxon->hasOption('js.app.minify'))
180
        {
181
            $jaxon->setOption('js.app.minify', $this->bMinifyJs);
182
        }
183
        if(!$jaxon->hasOption('js.app.uri') && $this->sJsUri != '')
184
        {
185
            $jaxon->setOption('js.app.uri', $this->sJsUri);
186
        }
187
        if(!$jaxon->hasOption('js.app.dir') && $this->sJsDir != '')
188
        {
189
            $jaxon->setOption('js.app.dir', $this->sJsDir);
190
        }
191
        // Set the request URI
192
        if(!$jaxon->hasOption('core.request.uri') && $this->sUri != '')
193
        {
194
            $jaxon->setOption('core.request.uri', $this->sUri);
195
        }
196
197
        // Event after setting up the module
198
        $this->triggerEvent('post.setup');
199
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
200
}
201