|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Config.php - Upload Trait |
|
5
|
|
|
* |
|
6
|
|
|
* The Jaxon class uses a modular plug-in system to facilitate the processing |
|
7
|
|
|
* of special Ajax requests made by a PHP page. |
|
8
|
|
|
* It generates Javascript that the page must include in order to make requests. |
|
9
|
|
|
* It handles the output of response commands (see <Jaxon\Response\Response>). |
|
10
|
|
|
* Many flags and settings can be adjusted to effect the behavior of the Jaxon class |
|
11
|
|
|
* as well as the client-side javascript. |
|
12
|
|
|
* |
|
13
|
|
|
* @package jaxon-core |
|
14
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
15
|
|
|
* @copyright 2017 Thierry Feuzeu <[email protected]> |
|
16
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
17
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Jaxon\Traits; |
|
21
|
|
|
|
|
22
|
|
|
use Jaxon\Utils\Config\Php; |
|
23
|
|
|
use Jaxon\Utils\Config\Yaml; |
|
24
|
|
|
use Jaxon\Utils\Config\Json; |
|
25
|
|
|
|
|
26
|
|
|
trait Config |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Set the default options of all components of the library |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
|
|
private function setDefaultOptions() |
|
34
|
|
|
{ |
|
35
|
|
|
// The default configuration settings. |
|
36
|
|
|
$this->setOptions(array( |
|
|
|
|
|
|
37
|
|
|
'core.version' => $this->getVersion(), |
|
|
|
|
|
|
38
|
|
|
'core.language' => 'en', |
|
39
|
|
|
'core.encoding' => 'utf-8', |
|
40
|
|
|
'core.decode_utf8' => false, |
|
41
|
|
|
'core.prefix.function' => 'jaxon_', |
|
42
|
|
|
'core.prefix.class' => 'Jaxon', |
|
43
|
|
|
'core.prefix.event' => 'jaxon_event_', |
|
44
|
|
|
// 'core.request.uri' => '', |
|
45
|
|
|
'core.request.mode' => 'asynchronous', |
|
46
|
|
|
'core.request.method' => 'POST', // W3C: Method is case sensitive |
|
47
|
|
|
'core.debug.on' => false, |
|
48
|
|
|
'core.debug.verbose' => false, |
|
49
|
|
|
'core.process.exit' => true, |
|
50
|
|
|
'core.process.clean' => false, |
|
51
|
|
|
'core.process.timeout' => 6000, |
|
52
|
|
|
'core.error.handle' => false, |
|
53
|
|
|
'core.error.log_file' => '', |
|
54
|
|
|
'js.lib.output_id' => 0, |
|
55
|
|
|
'js.lib.queue_size' => 0, |
|
56
|
|
|
'js.lib.load_timeout' => 2000, |
|
57
|
|
|
'js.lib.show_status' => false, |
|
58
|
|
|
'js.lib.show_cursor' => true, |
|
59
|
|
|
'js.app.dir' => '', |
|
60
|
|
|
'js.app.minify' => true, |
|
61
|
|
|
'js.app.options' => '', |
|
62
|
|
|
)); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Read and set Jaxon options from a PHP config file |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $sConfigFile The full path to the config file |
|
69
|
|
|
* @param string $sLibKey The key of the library options in the file |
|
70
|
|
|
* @param string|null $sAppKey The key of the application options in the file |
|
71
|
|
|
* |
|
72
|
|
|
* @return array |
|
73
|
|
|
*/ |
|
74
|
|
|
public function readPhpConfigFile($sConfigFile, $sLibKey = '', $sAppKey = null) |
|
75
|
|
|
{ |
|
76
|
|
|
return Php::read($sConfigFile, $sLibKey, $sAppKey); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Read and set Jaxon options from a YAML config file |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $sConfigFile The full path to the config file |
|
83
|
|
|
* @param string $sLibKey The key of the library options in the file |
|
84
|
|
|
* @param string|null $sAppKey The key of the application options in the file |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
|
|
public function readYamlConfigFile($sConfigFile, $sLibKey = '', $sAppKey = null) |
|
89
|
|
|
{ |
|
90
|
|
|
return Yaml::read($sConfigFile, $sLibKey, $sAppKey); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Read and set Jaxon options from a JSON config file |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $sConfigFile The full path to the config file |
|
97
|
|
|
* @param string $sLibKey The key of the library options in the file |
|
98
|
|
|
* @param string|null $sAppKey The key of the application options in the file |
|
99
|
|
|
* |
|
100
|
|
|
* @return array |
|
101
|
|
|
*/ |
|
102
|
|
|
public function readJsonConfigFile($sConfigFile, $sLibKey = '', $sAppKey = null) |
|
103
|
|
|
{ |
|
104
|
|
|
return Json::read($sConfigFile, $sLibKey, $sAppKey); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Read and set Jaxon options from a config file |
|
109
|
|
|
* |
|
110
|
|
|
* @param string $sConfigFile The full path to the config file |
|
111
|
|
|
* @param string $sLibKey The key of the library options in the file |
|
112
|
|
|
* @param string|null $sAppKey The key of the application options in the file |
|
113
|
|
|
* |
|
114
|
|
|
* @return array |
|
115
|
|
|
*/ |
|
116
|
|
|
public function readConfigFile($sConfigFile, $sLibKey = '', $sAppKey = null) |
|
117
|
|
|
{ |
|
118
|
|
|
$sExt = pathinfo($sConfigFile, PATHINFO_EXTENSION); |
|
119
|
|
|
switch($sExt) |
|
120
|
|
|
{ |
|
121
|
|
|
case 'php': |
|
122
|
|
|
return $this->readPhpConfigFile($sConfigFile, $sLibKey, $sAppKey); |
|
123
|
|
|
case 'yaml': |
|
124
|
|
|
case 'yml': |
|
125
|
|
|
return $this->readYamlConfigFile($sConfigFile, $sLibKey, $sAppKey); |
|
126
|
|
|
case 'json': |
|
127
|
|
|
return $this->readJsonConfigFile($sConfigFile, $sLibKey, $sAppKey); |
|
128
|
|
|
default: |
|
129
|
|
|
$sErrorMsg = jaxon_trans('config.errors.file.extension', array('path' => $sConfigFile)); |
|
130
|
|
|
throw new \Jaxon\Exception\Config\File($sErrorMsg); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.