Passed
Push — master ( 6251ab...a07882 )
by Thierry
01:53
created

AppTrait::package()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\App;
4
5
use Jaxon\Jaxon;
6
use Jaxon\Plugin\Package;
7
use Jaxon\Request\Factory\RequestFactory;
8
use Jaxon\Request\Handler\CallbackManager;
9
use Jaxon\Response\AbstractResponse;
10
use Jaxon\Session\SessionInterface;
11
use Jaxon\Ui\View\ViewRenderer;
12
use Jaxon\Utils\Http\UriException;
13
use Jaxon\Exception\RequestException;
14
use Jaxon\Exception\SetupException;
15
16
use Psr\Container\ContainerInterface;
17
use Psr\Log\LoggerInterface;
18
19
use Closure;
20
21
trait AppTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait AppTrait
Loading history...
22
{
23
    /**
24
     * @var Jaxon
25
     */
26
    protected $jaxon;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
27
28
    /**
29
     * Get the Jaxon application bootstrapper.
30
     *
31
     * @return Bootstrap
32
     */
33
    protected function bootstrap(): Bootstrap
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
34
    {
35
        return $this->jaxon->di()->getBootstrap();
36
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
37
38
    /**
39
     * Get the Jaxon response.
40
     *
41
     * @return AbstractResponse
42
     */
43
    public function ajaxResponse(): AbstractResponse
44
    {
45
        return $this->jaxon->getResponse();
46
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
47
48
    /**
49
     * Get an instance of a registered class
50
     *
51
     * @param string $sClassName The class name
52
     *
53
     * @return object|null
54
     * @throws SetupException
55
     */
56
    public function instance(string $sClassName)
57
    {
58
        return $this->jaxon->instance($sClassName);
59
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
60
61
    /**
62
     * Get a request to a registered class
63
     *
64
     * @param string $sClassName The class name
65
     *
66
     * @return RequestFactory|null
67
     * @throws SetupException
68
     */
69
    public function request(string $sClassName): ?RequestFactory
70
    {
71
        return $this->jaxon->request($sClassName);
72
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
73
74
    /**
75
     * Get a package instance
76
     *
77
     * @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...
78
     *
79
     * @return Package|null
80
     */
81
    public function package(string $sClassName): ?Package
82
    {
83
        return $this->jaxon->package($sClassName);
84
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
85
86
    /**
87
     * Get the request callback manager
88
     *
89
     * @return CallbackManager
90
     */
91
    public function callback(): CallbackManager
92
    {
93
        return $this->jaxon->callback();
94
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
95
96
    /**
97
     * Check if a call is a Jaxon request.
98
     *
99
     * @return bool
100
     */
101
    public function canProcessRequest(): bool
102
    {
103
        return $this->jaxon->canProcessRequest();
104
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
105
106
    /**
107
     * Get the HTTP response
108
     *
109
     * @param string $sCode    The HTTP response code
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
110
     *
111
     * @return mixed
112
     */
113
    abstract public function httpResponse(string $sCode = '200');
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
114
115
    /**
116
     * Process an incoming Jaxon request, and return the response.
117
     *
118
     * @return mixed
119
     * @throws RequestException
120
     */
121
    public function processRequest()
122
    {
123
        // Prevent the Jaxon library from sending the response or exiting
124
        $this->jaxon->config()->setOption('core.response.send', false);
125
        $this->jaxon->config()->setOption('core.process.exit', false);
126
127
        // Process the jaxon request
128
        $this->jaxon->processRequest();
129
130
        // Return the response to the request
131
        return $this->httpResponse();
132
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
133
134
    /**
135
     * Get the HTML tags to include Jaxon CSS code and files into the page.
136
     *
137
     * @return string  the javascript code
138
     */
139
    public function css(): string
140
    {
141
        return $this->jaxon->getCss();
142
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
143
144
    /**
145
     * Get the HTML tags to include Jaxon CSS code and files into the page.
146
     *
147
     * @return string  the javascript code
148
     */
149
    public function getCss(): string
150
    {
151
        return $this->jaxon->getCss();
152
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
153
154
    /**
155
     * Get the HTML tags to include Jaxon javascript files into the page.
156
     *
157
     * @return string  the javascript code
158
     */
159
    public function js(): string
160
    {
161
        return $this->jaxon->getJs();
162
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
163
164
    /**
165
     * Get the HTML tags to include Jaxon javascript files into the page.
166
     *
167
     * @return string  the javascript code
168
     */
169
    public function getJs(): string
170
    {
171
        return $this->jaxon->getJs();
172
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
173
174
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $bIncludeCss should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $bIncludeJs should have a doc-comment as per coding-style.
Loading history...
175
     * Get the javascript code to be sent to the browser.
176
     *
177
     * @return string  the javascript code
178
     * @throws UriException
179
     */
180
    public function script(bool $bIncludeJs = false, bool $bIncludeCss = false): string
181
    {
182
        return $this->jaxon->getScript($bIncludeJs, $bIncludeCss);
183
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
184
185
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $bIncludeCss should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $bIncludeJs should have a doc-comment as per coding-style.
Loading history...
186
     * Get the javascript code to be sent to the browser.
187
     *
188
     * @return string  the javascript code
189
     * @throws UriException
190
     */
191
    public function getScript(bool $bIncludeJs = false, bool $bIncludeCss = false): string
192
    {
193
        return $this->jaxon->getScript($bIncludeJs, $bIncludeCss);
194
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
195
196
    /**
197
     * Get the view renderer
198
     *
199
     * @return ViewRenderer
200
     */
201
    public function view(): ViewRenderer
202
    {
203
        return $this->jaxon->view();
204
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
205
206
    /**
207
     * Get the session manager
208
     *
209
     * @return SessionInterface
210
     */
211
    public function session(): SessionInterface
212
    {
213
        return $this->jaxon->session();
214
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
215
216
    /**
217
     * Get the logger
218
     *
219
     * @return LoggerInterface
220
     */
221
    public function logger(): LoggerInterface
222
    {
223
        return $this->jaxon->logger();
224
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
225
226
    /**
227
     * Sets a logger.
228
     *
229
     * @param LoggerInterface $logger
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
230
     *
231
     * @return void
232
     */
233
    public function setLogger(LoggerInterface $logger)
234
    {
235
        $this->jaxon->setLogger($logger);
236
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
237
238
    /**
239
     * Set the container provided by the integrated framework
240
     *
241
     * @param ContainerInterface $xContainer    The container implementation
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
242
     *
243
     * @return void
244
     */
245
    public function setAppContainer(ContainerInterface $xContainer)
246
    {
247
        $this->jaxon->di()->setAppContainer($xContainer);
248
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
249
250
    /**
251
     * Add a view namespace, and set the corresponding renderer.
252
     *
253
     * @param string $sNamespace    The namespace name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
254
     * @param string $sDirectory    The namespace directory
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
255
     * @param string $sExtension    The extension to append to template names
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
256
     * @param string $sRenderer    The corresponding renderer name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter name; 4 found
Loading history...
257
     *
258
     * @return void
259
     */
260
    public function addViewNamespace(string $sNamespace, string $sDirectory, string $sExtension, string $sRenderer)
261
    {
262
        $this->jaxon->di()->getViewManager()->addNamespace($sNamespace, $sDirectory, $sExtension, $sRenderer);
263
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
264
265
    /**
266
     * Add a view renderer with an id
267
     *
268
     * @param string $sId    The unique identifier of the view renderer
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...
269
     * @param Closure $xClosure    A closure to create the view instance
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
270
     *
271
     * @return void
272
     */
273
    public function addViewRenderer(string $sId, Closure $xClosure)
274
    {
275
        $this->jaxon->di()->getViewManager()->addRenderer($sId, $xClosure);
276
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
277
278
    /**
279
     * Set the session manager
280
     *
281
     * @param Closure $xClosure    A closure to create the session manager instance
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
282
     *
283
     * @return void
284
     */
285
    public function setSessionManager(Closure $xClosure)
286
    {
287
        $this->jaxon->di()->setSessionManager($xClosure);
288
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
289
}
290