1 | <?php |
||
42 | class Ini extends Abstracts\Engine\Ini implements Interfaces\Engine\Ini |
||
43 | { |
||
44 | public function __construct(Interfaces\Engine $php) |
||
50 | |||
51 | /** |
||
52 | * @param string $pickleSection |
||
53 | * @param array $dlls |
||
|
|||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | protected function rebuildPickleParts($pickleSection, array $dlls_add, array $dlls_del = array()) |
||
58 | { |
||
59 | 1 | $lines = explode("\n", $pickleSection); |
|
60 | 1 | $new = []; |
|
61 | |||
62 | /* First add the lines for exts that are requested to be added. */ |
||
63 | 1 | foreach ($dlls_add as $dll) { |
|
64 | 1 | $new[] = $this->buildDllIniLine($dll); |
|
65 | } |
||
66 | |||
67 | /* Then, go over the existing lines, restore those that are not |
||
68 | requested to be deleted and not already added. */ |
||
69 | 1 | foreach ($lines as $l) { |
|
70 | 1 | $l = trim($l); |
|
71 | 1 | if (0 !== strpos($l, 'extension')) { |
|
72 | 1 | continue; |
|
73 | } |
||
74 | 1 | list(, $dllname) = explode('=', $l); |
|
75 | |||
76 | 1 | if (in_array(trim($dllname), $dlls_add)) { |
|
77 | /* don't create a duplicated item */ |
||
78 | 1 | continue; |
|
79 | } |
||
80 | 1 | if (in_array(trim($dllname), $dlls_del)) { |
|
81 | /* don't restore as it should be deleted */ |
||
82 | 1 | continue; |
|
83 | } |
||
84 | 1 | $new[] = $l; |
|
85 | } |
||
86 | |||
87 | 1 | sort($new); |
|
88 | |||
89 | 1 | return implode("\n", $new); |
|
90 | } |
||
91 | |||
92 | protected function setupPickleSectionPositions() |
||
93 | { |
||
94 | 1 | $posHeader = strpos($this->raw, self::PICKLE_HEADER); |
|
95 | 1 | if (false === $posHeader) { |
|
96 | /* no pickle section here yet */ |
||
97 | 1 | $this->pickleHeaderStartPos = strlen($this->raw); |
|
98 | |||
99 | 1 | return; |
|
100 | } |
||
101 | |||
102 | 1 | $this->pickleHeaderStartPos = $posHeader; |
|
103 | 1 | $this->pickleHeaderEndPos = $this->pickleHeaderStartPos + strlen(self::PICKLE_HEADER); |
|
104 | |||
105 | 1 | $posFooter = strpos($this->raw, self::PICKLE_FOOTER); |
|
106 | 1 | if (false === $posFooter) { |
|
107 | /* This is bad, no end of section marker, will have to lookup. The strategy is |
||
108 | - look for the last extension directve after the header |
||
109 | - extension directives are expected to come one after another one per line |
||
110 | - comments are not expected inbetveen |
||
111 | - mark the next pos after the last extension directive as the footer pos |
||
112 | */ |
||
113 | 1 | $pos = $this->pickleHeaderEndPos; |
|
114 | do { |
||
115 | 1 | $pos = strpos($this->raw, 'extension', $pos); |
|
116 | 1 | if (false !== $pos) { |
|
117 | 1 | $this->pickleFooterStartPos = $pos; |
|
118 | 1 | ++$pos; |
|
119 | } |
||
120 | 1 | } while (false !== $pos); |
|
121 | |||
122 | 1 | $this->pickleFooterStartPos = strpos($this->raw, "\n", $this->pickleFooterStartPos); |
|
123 | } else { |
||
124 | 1 | $this->pickleFooterStartPos = $posFooter; |
|
125 | 1 | $this->pickleFooterEndPos = $this->pickleFooterStartPos + strlen(self::PICKLE_FOOTER); |
|
126 | } |
||
127 | 1 | } |
|
128 | |||
129 | public function updatePickleSection(array $dlls_add, array $dlls_del = array()) |
||
130 | { |
||
131 | 1 | $before = ''; |
|
132 | 1 | $after = ''; |
|
133 | |||
134 | 1 | $pickleSection = $this->rebuildPickleParts($this->getPickleSection(), $dlls_add, $dlls_del); |
|
135 | |||
136 | 1 | $before = substr($this->raw, 0, $this->pickleHeaderStartPos); |
|
137 | |||
138 | /* If the footer end pos is < 0, there was no footer in php.ini. In this case the footer start pos |
||
139 | means the end of the last extension directive after the header start, where the footer should be */ |
||
140 | 1 | if ($this->pickleFooterEndPos > 0) { |
|
141 | 1 | $after = substr($this->raw, $this->pickleFooterEndPos); |
|
142 | } else { |
||
143 | 1 | $after = substr($this->raw, $this->pickleFooterStartPos); |
|
144 | } |
||
145 | |||
146 | 1 | $before = rtrim($before); |
|
147 | 1 | $after = ltrim($after); |
|
148 | |||
149 | 1 | $this->raw = $before."\n\n".self::PICKLE_HEADER."\n".trim($pickleSection)."\n".self::PICKLE_FOOTER."\n\n".$after; |
|
150 | 1 | if (!@file_put_contents($this->path, $this->raw)) { |
|
151 | throw new \Exception('Cannot update php.ini'); |
||
152 | } |
||
153 | 1 | } |
|
154 | |||
155 | protected function buildDllIniLine($dll) |
||
159 | } |
||
160 | |||
161 | /* vim: set tabstop=4 shiftwidth=4 expandtab: fdm=marker */ |
||
162 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.