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 MIT |
8
|
|
|
* |
9
|
|
|
* LICENSE: |
10
|
|
|
* |
11
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
12
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
13
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
14
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
15
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
16
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
17
|
|
|
* THE SOFTWARE. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
class DefaultConfiguration { |
21
|
|
|
|
22
|
|
|
private static $configuration = array( |
23
|
|
|
'enabled' => true, |
24
|
|
|
'encoding' => 'UTF-8', |
25
|
|
|
'disabled-status' => 503, |
26
|
|
|
'disabled-message' => 'Dispatcher offline' |
27
|
|
|
); |
28
|
|
|
|
29
|
4 |
|
public static function get() { |
30
|
|
|
|
31
|
4 |
|
$config = self::$configuration; |
32
|
|
|
|
33
|
4 |
|
$config['base-path'] = getcwd(); |
34
|
|
|
|
35
|
4 |
|
$config['base-url'] = self::getAbsoluteUrl(); |
36
|
|
|
|
37
|
4 |
|
$config['base-uri'] = self::getAbsoluteUri(); |
38
|
|
|
|
39
|
4 |
|
$config['base-location'] = self::getAbsoluteLocation(); |
40
|
|
|
|
41
|
4 |
|
return $config; |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
4 |
|
private static function getAbsoluteUrl() { |
46
|
|
|
|
47
|
4 |
|
$http = self::getHttpSchema(); |
48
|
|
|
|
49
|
4 |
|
$location = self::getAbsoluteLocation(); |
50
|
|
|
|
51
|
4 |
|
return ($http.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost').$location."/"); |
|
|
|
|
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
4 |
|
private static function getAbsoluteLocation() { |
56
|
|
|
|
57
|
4 |
|
return preg_replace("/\/index.php(.*?)$/i", "", $_SERVER['PHP_SELF']); |
|
|
|
|
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
4 |
|
private static function getAbsoluteUri() { |
62
|
|
|
|
63
|
4 |
|
$http = self::getHttpSchema(); |
64
|
|
|
|
65
|
4 |
|
return "$http$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
|
|
|
|
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
4 |
|
private static function getHttpSchema() { |
70
|
|
|
|
71
|
4 |
|
return 'http'.((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '').'://'; |
|
|
|
|
72
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.