1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of WebHelper Parser. |
5
|
|
|
* |
6
|
|
|
* (c) James <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WebHelper\Parser\Parser; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Methods that can be applied depending of the kind of server after a parsed configuration file turns into an array. |
16
|
|
|
* |
17
|
|
|
* @author James <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class After |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Trim all blank lines. |
23
|
|
|
* |
24
|
|
|
* @param array $activeConfig config file exploded in an array of lines |
25
|
|
|
* |
26
|
|
|
* @return array an array cleaned of blank lines |
27
|
|
|
*/ |
28
|
11 |
|
public static function deleteBlankLines(array $activeConfig = array()) |
29
|
|
|
{ |
30
|
11 |
|
$cleanedActiveConfig = []; |
31
|
|
|
|
32
|
11 |
|
foreach (array_map('trim', $activeConfig) as $line) { |
33
|
11 |
|
if ($line != '') { |
34
|
9 |
|
$cleanedActiveConfig[] = $line; |
35
|
9 |
|
} |
36
|
11 |
|
} |
37
|
|
|
|
38
|
11 |
|
return $cleanedActiveConfig; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Reassembles discontinued simple directives in one line. |
43
|
|
|
* |
44
|
|
|
* In an Apache server context, it may be encountered. |
45
|
|
|
* |
46
|
|
|
* @param array $activeConfig config file exploded in an array of lines |
47
|
|
|
* |
48
|
|
|
* @return array an array with continuing lines gathered as one |
49
|
|
|
*/ |
50
|
5 |
|
public static function continuingDirectives(array $activeConfig = array()) |
51
|
|
|
{ |
52
|
5 |
|
$cleanedActiveConfig = []; |
53
|
|
|
|
54
|
|
|
//Continuing directives with "\" at the very end of a line are reassembled |
55
|
5 |
|
foreach ($activeConfig as $line) { |
56
|
5 |
|
if (!static::setLineIfPrevious($line)) { |
|
|
|
|
57
|
5 |
|
$cleanedActiveConfig[] = $line; |
58
|
5 |
|
} |
59
|
5 |
|
} |
60
|
|
|
|
61
|
5 |
|
return $cleanedActiveConfig; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Helps to gather continuing lines as one. |
66
|
|
|
* |
67
|
|
|
* @param string &$line a line to add to previous lines or matching a contuining end line marker |
68
|
|
|
*/ |
69
|
5 |
|
private static function setLineIfPrevious(&$line) |
70
|
|
|
{ |
71
|
5 |
|
static $previousLine = ''; |
72
|
|
|
|
73
|
5 |
|
if ($previousLine) { |
74
|
1 |
|
$line = $previousLine.' '.trim($line); |
75
|
1 |
|
$previousLine = ''; |
76
|
1 |
|
} |
77
|
|
|
|
78
|
5 |
|
if (preg_match('/(.+)\\\$/', $line, $container)) { |
79
|
1 |
|
$previousLine = $container[1]; |
80
|
1 |
|
} |
81
|
|
|
|
82
|
5 |
|
return $previousLine; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: