Passed
Push — master ( 5b7bca...888408 )
by Thierry
02:13
created

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