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

App::processRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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