|
1
|
|
|
<?php namespace Comodojo\Dispatcher\Components; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package Comodojo Dispatcher |
|
5
|
|
|
* @author Marco Giovinazzi <[email protected]> |
|
6
|
|
|
* @author Marco Castiello <[email protected]> |
|
7
|
|
|
* @license GPL-3.0+ |
|
8
|
|
|
* |
|
9
|
|
|
* LICENSE: |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class DefaultConfiguration { |
|
27
|
|
|
|
|
28
|
|
|
private static $configuration = array( |
|
29
|
|
|
'enabled' => true, |
|
30
|
|
|
'encoding' => 'UTF-8', |
|
31
|
|
|
'disabled-status' => 503, |
|
32
|
|
|
'disabled-message' => 'Dispatcher offline', |
|
33
|
|
|
'supported-methods' => array('GET','PUT','POST','DELETE','OPTIONS','HEAD') |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
public static function get() { |
|
37
|
|
|
|
|
38
|
|
|
$config = self::$configuration; |
|
39
|
|
|
|
|
40
|
|
|
$config['base-path'] = getcwd(); |
|
41
|
|
|
|
|
42
|
|
|
$config['base-url'] = self::urlGetAbsolute(); |
|
43
|
|
|
|
|
44
|
|
|
$config['base-uri'] = self::uriGetAbsolute(); |
|
45
|
|
|
|
|
46
|
|
|
return $config; |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private static function urlGetAbsolute() { |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
$http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://'; |
|
53
|
|
|
|
|
54
|
|
|
$uri = self::uriGetAbsolute(); |
|
55
|
|
|
|
|
56
|
|
|
return ( $http . $_SERVER['HTTP_HOST'] . $uri . "/" ); |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private static function uriGetAbsolute() { |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
return preg_replace("/\/index.php(.*?)$/i", "", $_SERVER['PHP_SELF']); |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: