Passed
Push — master ( 6eb156...b34d93 )
by Thierry
04:25
created

AppTrait::uri()   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\ResponseInterface;
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
use function trim;
22
23
trait AppTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait AppTrait
Loading history...
24
{
25
    /**
26
     * @var Jaxon
27
     */
28
    protected $jaxon;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
29
30
    /**
31
     * Get the Jaxon application bootstrapper.
32
     *
33
     * @return Bootstrap
34
     */
35
    protected function bootstrap(): Bootstrap
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
36
    {
37
        return $this->jaxon->di()->getBootstrap();
38
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
39
40
    /**
41
     * Set the ajax endpoint URI
42
     *
43
     * @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...
44
     *
45
     * @return void
46
     */
47
    public function uri(string $sUri)
48
    {
49
        $this->jaxon->setOption('core.request.uri', $sUri);
50
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
51
52
    /**
53
     * Get the Jaxon response.
54
     *
55
     * @return ResponseInterface
56
     */
57
    public function ajaxResponse(): ResponseInterface
58
    {
59
        return $this->jaxon->getResponse();
60
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
61
62
    /**
63
     * Get the configured character encoding
64
     *
65
     * @return string
66
     */
67
    public function getCharacterEncoding(): string
68
    {
69
        return trim($this->jaxon->getOption('core.encoding', ''));
70
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
71
72
    /**
73
     * Get the content type of the HTTP response
74
     *
75
     * @return string
76
     */
77
    public function getContentType(): string
78
    {
79
        return $this->jaxon->di()->getResponseManager()->getContentType();
80
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
81
82
    /**
83
     * Get an instance of a registered class
84
     *
85
     * @param string $sClassName The class name
86
     *
87
     * @return object|null
88
     * @throws SetupException
89
     */
90
    public function instance(string $sClassName)
91
    {
92
        return $this->jaxon->instance($sClassName);
93
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
94
95
    /**
96
     * Get a request to a registered class
97
     *
98
     * @param string $sClassName The class name
99
     *
100
     * @return RequestFactory|null
101
     * @throws SetupException
102
     */
103
    public function request(string $sClassName): ?RequestFactory
104
    {
105
        return $this->jaxon->request($sClassName);
106
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
107
108
    /**
109
     * Get a package instance
110
     *
111
     * @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...
112
     *
113
     * @return Package|null
114
     */
115
    public function package(string $sClassName): ?Package
116
    {
117
        return $this->jaxon->package($sClassName);
118
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
119
120
    /**
121
     * Get the request callback manager
122
     *
123
     * @return CallbackManager
124
     */
125
    public function callback(): CallbackManager
126
    {
127
        return $this->jaxon->callback();
128
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
129
130
    /**
131
     * Check if a call is a Jaxon request.
132
     *
133
     * @return bool
134
     */
135
    public function canProcessRequest(): bool
136
    {
137
        return $this->jaxon->canProcessRequest();
138
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
139
140
    /**
141
     * Get the HTTP response
142
     *
143
     * @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...
144
     *
145
     * @return mixed
146
     */
147
    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...
148
149
    /**
150
     * Process an incoming Jaxon request, and return the response.
151
     *
152
     * @return mixed
153
     * @throws RequestException
154
     */
155
    public function processRequest()
156
    {
157
        // Process the jaxon request
158
        $this->jaxon->processRequest();
159
160
        // Return the response to the request
161
        return $this->httpResponse();
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 CSS code and files into the page.
166
     *
167
     * @return string  the javascript code
168
     */
169
    public function css(): string
170
    {
171
        return $this->jaxon->getCss();
172
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
173
174
    /**
175
     * Get the HTML tags to include Jaxon CSS code and files into the page.
176
     *
177
     * @return string  the javascript code
178
     */
179
    public function getCss(): string
180
    {
181
        return $this->jaxon->getCss();
182
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
183
184
    /**
185
     * Get the HTML tags to include Jaxon javascript files into the page.
186
     *
187
     * @return string  the javascript code
188
     */
189
    public function js(): string
190
    {
191
        return $this->jaxon->getJs();
192
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
193
194
    /**
195
     * Get the HTML tags to include Jaxon javascript files into the page.
196
     *
197
     * @return string  the javascript code
198
     */
199
    public function getJs(): string
200
    {
201
        return $this->jaxon->getJs();
202
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
203
204
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $bIncludeJs should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $bIncludeCss should have a doc-comment as per coding-style.
Loading history...
205
     * Get the javascript code to be sent to the browser.
206
     *
207
     * @return string  the javascript code
208
     * @throws UriException
209
     */
210
    public function script(bool $bIncludeJs = false, bool $bIncludeCss = false): string
211
    {
212
        return $this->jaxon->getScript($bIncludeJs, $bIncludeCss);
213
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
214
215
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $bIncludeJs should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $bIncludeCss should have a doc-comment as per coding-style.
Loading history...
216
     * Get the javascript code to be sent to the browser.
217
     *
218
     * @return string  the javascript code
219
     * @throws UriException
220
     */
221
    public function getScript(bool $bIncludeJs = false, bool $bIncludeCss = false): string
222
    {
223
        return $this->jaxon->getScript($bIncludeJs, $bIncludeCss);
224
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
225
226
    /**
227
     * Get the view renderer
228
     *
229
     * @return ViewRenderer
230
     */
231
    public function view(): ViewRenderer
232
    {
233
        return $this->jaxon->view();
234
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
235
236
    /**
237
     * Get the session manager
238
     *
239
     * @return SessionInterface
240
     */
241
    public function session(): SessionInterface
242
    {
243
        return $this->jaxon->session();
244
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
245
246
    /**
247
     * Get the logger
248
     *
249
     * @return LoggerInterface
250
     */
251
    public function logger(): LoggerInterface
252
    {
253
        return $this->jaxon->di()->logger();
254
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
255
256
    /**
257
     * Sets a logger.
258
     *
259
     * @param LoggerInterface $logger
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
260
     *
261
     * @return void
262
     */
263
    public function setLogger(LoggerInterface $logger)
264
    {
265
        $this->jaxon->di()->setLogger($logger);
266
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
267
268
    /**
269
     * Set the container provided by the integrated framework
270
     *
271
     * @param ContainerInterface $xContainer    The container implementation
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
272
     *
273
     * @return void
274
     */
275
    public function setAppContainer(ContainerInterface $xContainer)
276
    {
277
        $this->jaxon->di()->setAppContainer($xContainer);
278
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
279
280
    /**
281
     * Add a view namespace, and set the corresponding renderer.
282
     *
283
     * @param string $sNamespace    The namespace name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
284
     * @param string $sDirectory    The namespace directory
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
285
     * @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...
286
     * @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...
287
     *
288
     * @return void
289
     */
290
    public function addViewNamespace(string $sNamespace, string $sDirectory, string $sExtension, string $sRenderer)
291
    {
292
        $this->jaxon->di()->getViewManager()->addNamespace($sNamespace, $sDirectory, $sExtension, $sRenderer);
293
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
294
295
    /**
296
     * Add a view renderer with an id
297
     *
298
     * @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...
299
     * @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...
300
     *
301
     * @return void
302
     */
303
    public function addViewRenderer(string $sId, Closure $xClosure)
304
    {
305
        $this->jaxon->di()->getViewManager()->addRenderer($sId, $xClosure);
306
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
307
308
    /**
309
     * Set the session manager
310
     *
311
     * @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...
312
     *
313
     * @return void
314
     */
315
    public function setSessionManager(Closure $xClosure)
316
    {
317
        $this->jaxon->di()->setSessionManager($xClosure);
318
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
319
}
320