RequestTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 47
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canProcessRequest() 0 3 1
A processRequest() 0 6 1
1
<?php
2
3
/**
4
 * ResponseTrait.php
5
 *
6
 * Send Jaxon ajax response.
7
 *
8
 * @package jaxon-core
9
 * @author Jared White
10
 * @author J. Max Wilson
11
 * @author Thierry Feuzeu
12
 * @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
13
 * @copyright 2022 Thierry Feuzeu <[email protected]>
14
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
15
 * @link https://github.com/jaxon-php/jaxon-core
16
 */
17
18
namespace Jaxon\App\Ajax\Traits;
19
20
use Jaxon\Exception\RequestException;
21
use Jaxon\Request\Handler\RequestHandler;
22
23
trait RequestTrait
24
{
25
    /**
26
     * @return RequestHandler
27
     */
28
    abstract protected function getRequestHandler(): RequestHandler;
29
30
    /**
31
     * Get the HTTP response
32
     *
33
     * @param string $sCode    The HTTP response code
34
     *
35
     * @return mixed
36
     */
37
    abstract public function httpResponse(string $sCode = '200'): mixed;
38
39
    /**
40
     * Determine if a call is a jaxon request
41
     *
42
     * @return bool
43
     */
44
    public function canProcessRequest(): bool
45
    {
46
        return $this->getRequestHandler()->canProcessRequest();
47
    }
48
49
    /**
50
     * If this is a jaxon request, call the requested PHP function, build the response and send it back to the browser
51
     *
52
     * This is the main server side engine for Jaxon.
53
     * It handles all the incoming requests, including the firing of events and handling of the response.
54
     * If your RequestURI is the same as your web page, then this function should be called before ANY
55
     * headers or HTML is output from your script.
56
     *
57
     * This function may exit after the request is processed, if the 'core.process.exit' option is set to true.
58
     *
59
     * @return mixed
60
     *
61
     * @throws RequestException
62
     * @see <canProcessRequest>
63
     */
64
    public function processRequest(): mixed
65
    {
66
        // Process the jaxon request
67
        $this->getRequestHandler()->processRequest();
68
69
        return $this->httpResponse();
70
    }
71
}
72