App::httpResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * App.php
5
 *
6
 * Jaxon application
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2019 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\App\Ajax;
16
17
use Jaxon\Exception\RequestException;
18
use Jaxon\Exception\SetupException;
19
20
use function file_exists;
21
use function is_array;
22
23
class App extends AbstractApp
24
{
25
    use SendTrait;
26
27
    /**
28
     * @inheritDoc
29
     * @throws SetupException
30
     */
31
    public function setup(string $sConfigFile = '')
32
    {
33
        if(!file_exists($sConfigFile))
34
        {
35
            $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]);
36
            throw new SetupException($sMessage);
37
        }
38
39
        // Read the config options.
40
        $aOptions = $this->xConfigManager->read($sConfigFile);
41
        $aLibOptions = $aOptions['lib'] ?? [];
42
        $aAppOptions = $aOptions['app'] ?? [];
43
        if(!is_array($aLibOptions) || !is_array($aAppOptions))
44
        {
45
            $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]);
46
            throw new SetupException($sMessage);
47
        }
48
        // The bootstrap set this to false. It needs to be changed.
49
        if(!isset($aLibOptions['core']['response']['send']))
50
        {
51
            $aLibOptions['core']['response']['send'] = true;
52
        }
53
54
        $this->bootstrap()
55
            ->lib($aLibOptions)
56
            ->app($aAppOptions)
57
            ->setup();
58
    }
59
60
    /**
61
     * @inheritDoc
62
     * @throws RequestException
63
     */
64
    public function httpResponse(string $sCode = '200')
65
    {
66
        // Send the response
67
        $this->sendResponse($sCode);
68
    }
69
}
70