|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* App.php - Jaxon application |
|
5
|
|
|
* |
|
6
|
|
|
* @package jaxon-core |
|
7
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
8
|
|
|
* @copyright 2019 Thierry Feuzeu <[email protected]> |
|
9
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
10
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Jaxon\App; |
|
14
|
|
|
|
|
15
|
|
|
use Jaxon\Utils\Session\Manager as SessionManager; |
|
16
|
|
|
use Exception; |
|
17
|
|
|
|
|
18
|
|
|
class App |
|
19
|
|
|
{ |
|
20
|
|
|
use \Jaxon\Features\App; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Read config options from a config file and setup the library |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $sConfigFile The full path to the config file |
|
26
|
|
|
* |
|
27
|
|
|
* @return Jaxon |
|
28
|
|
|
*/ |
|
29
|
|
|
public function setup($sConfigFile) |
|
30
|
|
|
{ |
|
31
|
|
|
if(!file_exists($sConfigFile)) |
|
32
|
|
|
{ |
|
33
|
|
|
throw new Exception("Unable to find config file at $sConfigFile"); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
// Read the config options. |
|
37
|
|
|
$aOptions = jaxon()->config()->read($sConfigFile); |
|
38
|
|
|
$aLibOptions = key_exists('lib', $aOptions) ? $aOptions['lib'] : []; |
|
39
|
|
|
$aAppOptions = key_exists('app', $aOptions) ? $aOptions['app'] : []; |
|
40
|
|
|
|
|
41
|
|
|
if(!is_array($aLibOptions) || !is_array($aAppOptions)) |
|
42
|
|
|
{ |
|
43
|
|
|
throw new Exception("Unexpected content in config file at $sConfigFile"); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// Set the session manager |
|
47
|
|
|
jaxon()->di()->setSessionManager(function () { |
|
48
|
|
|
return new SessionManager(); |
|
49
|
|
|
}); |
|
50
|
|
|
|
|
51
|
|
|
$this->bootstrap() |
|
52
|
|
|
->lib($aLibOptions) |
|
53
|
|
|
->app($aAppOptions) |
|
54
|
|
|
// ->uri($sUri) |
|
55
|
|
|
// ->js(!$isDebug, $sJsUrl, $sJsDir, !$isDebug) |
|
56
|
|
|
->run(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get the HTTP response |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $code The HTTP response code |
|
63
|
|
|
* |
|
64
|
|
|
* @return mixed |
|
65
|
|
|
*/ |
|
66
|
|
|
public function httpResponse($code = '200') |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
// Nothing to do |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Process an incoming Jaxon request, and return the response. |
|
73
|
|
|
* |
|
74
|
|
|
* @return void |
|
75
|
|
|
*/ |
|
76
|
|
|
public function processRequest() |
|
77
|
|
|
{ |
|
78
|
|
|
return jaxon()->processRequest(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.