1 | <?php |
||
19 | class Config |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Default configuration options |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $default_config = [ |
||
27 | 'java_bin' => 'java', |
||
28 | 'server_jar' => '{base_dir}/resources/pjb621_standalone/JavaBridge.jar', |
||
29 | 'log_file' => '{base_dir}/var/pjbserver-port{tcp_port}.log', |
||
30 | 'pid_file' => '{base_dir}/var/pjbserver-port{tcp_port}.pid', |
||
31 | 'classpaths' => [], |
||
32 | 'threads' => 50 |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * Internal configuration array |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $config; |
||
40 | |||
41 | |||
42 | /** |
||
43 | * Constructor |
||
44 | * |
||
45 | * <code> |
||
46 | * |
||
47 | * $params = [ |
||
48 | * // Port (required) |
||
49 | * 'port' => 8089, |
||
50 | * |
||
51 | * // Classpath autoloads (optional) |
||
52 | * 'classpaths' => [ |
||
53 | * '/my/path/to_specific/jar_file.jar', |
||
54 | * '/my/path/to_all_jars/*.jar' |
||
55 | * ], |
||
56 | * |
||
57 | * 'threads' => 50, |
||
58 | * |
||
59 | * // Defaults (optional) |
||
60 | * 'java_bin' => 'java', |
||
61 | * 'server_jar' => '{base_dir}/resources/pjb621_standalone/JavaBridge.jar', |
||
62 | * 'log_file' => '{base_dir}/var/pjbserver-port{tcp_port}.log', |
||
63 | * 'pid_file' => '{base_dir}/var/pjbserver-port{tcp_port}.pid' |
||
64 | * |
||
65 | * ]; |
||
66 | * $config = new StandaloneServer\Config($params); |
||
67 | * </code> |
||
68 | * |
||
69 | * @throws Exception\InvalidArgumentException |
||
70 | * @param array $config |
||
71 | * |
||
72 | */ |
||
73 | 30 | public function __construct(array $config) |
|
84 | |||
85 | /** |
||
86 | * Return port on which standalone server listens |
||
87 | * @return int |
||
88 | */ |
||
89 | 18 | public function getPort() |
|
93 | |||
94 | /** |
||
95 | * Return jar file of the server |
||
96 | * @return string |
||
97 | */ |
||
98 | 18 | public function getServerJar() |
|
102 | |||
103 | |||
104 | /** |
||
105 | * Return java binary |
||
106 | * @return string |
||
107 | */ |
||
108 | 18 | public function getJavaBin() |
|
112 | |||
113 | /** |
||
114 | * Return log file |
||
115 | * @return string |
||
116 | */ |
||
117 | 18 | public function getLogFile() |
|
121 | |||
122 | /** |
||
123 | * Return an array containing the java classpath(s) for the server |
||
124 | * @return array |
||
125 | */ |
||
126 | 18 | public function getClasspaths() |
|
130 | |||
131 | /** |
||
132 | * Return pid file where to store process id |
||
133 | * @return string |
||
134 | */ |
||
135 | 20 | public function getPidFile() |
|
139 | |||
140 | |||
141 | /** |
||
142 | * Return standalone server threads |
||
143 | * |
||
144 | * @return int|string |
||
145 | */ |
||
146 | 15 | public function getThreads() |
|
150 | |||
151 | /** |
||
152 | * Return standalone configuration |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | 4 | public function getConfig() |
|
160 | |||
161 | /** |
||
162 | * Return default configuration options |
||
163 | * @param int $port |
||
164 | * @return array |
||
165 | */ |
||
166 | 26 | protected function getDefaultConfig($port) |
|
177 | |||
178 | /** |
||
179 | * Return pjbserver-tools installation base directory |
||
180 | * |
||
181 | * @throws Exception\RuntimeException |
||
182 | * @return string |
||
183 | */ |
||
184 | 26 | public function getBaseDir() |
|
196 | |||
197 | /** |
||
198 | * Check configuration parameters |
||
199 | * @throws Exception\InvalidArgumentException |
||
200 | * @param array $config |
||
201 | */ |
||
202 | 26 | protected function checkConfig(array $config) |
|
277 | } |
||
278 |