This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /******************************************************************** |
||
3 | * Created by: Marko Kungla @ OkramLabs on Aug 6, 2012 - 9:21:34 |
||
4 | * Contact: [email protected] - https://okramlabs.com |
||
5 | * @copyright: 2015 OkramLabs - https://okramlabs.com |
||
6 | * @license MIT |
||
7 | * |
||
8 | * Package name:libhowi-filesystem |
||
9 | * @category HOWI3 |
||
10 | * @package libhowi |
||
11 | * @subpackage filesystem |
||
12 | * |
||
13 | * Lang: PHP |
||
14 | * Encoding: UTF-8 |
||
15 | * File: Filesystem.inc |
||
16 | * @link https:// |
||
17 | ******************************************************************** |
||
18 | * Contributors: |
||
19 | * @author Marko Kungla <[email protected]> |
||
20 | * Github: https://github.com/mkungla |
||
21 | ******************************************************************** |
||
22 | * Comments: |
||
23 | */ |
||
24 | namespace HOWI3\libhowi\Filesystem\php7; |
||
25 | |||
26 | use \HOWI3\libhowi\Filesystem\Commons\AbstractFilesystem; |
||
27 | use \HOWI3\libhowi\Filesystem\Commons\FilesystemInterface; |
||
28 | use \HOWI3\libhowi\Filesystem\Commons\SharedMethodsInterface; |
||
29 | use \HOWI3\libhowi\Filesystem\Commons\TraitForResponse; |
||
30 | use \HOWI3\libhowi\Filesystem\php7\Objects\DirectoryPlaceholderObject; |
||
31 | use \HOWI3\libhowi\Filesystem\php7\Objects\DirectoryTreeObject; |
||
32 | use \HOWI3\libhowi\Filesystem\php7\Objects\FileObject; |
||
33 | use \HOWI3\libhowi\Filesystem\php7\Objects\InfoObject; |
||
34 | use \HOWI3\libhowi\Filesystem\php7\Objects\TmpObject; |
||
35 | use \HOWI3\libhowi\Filesystem\php7\Objects\LinkObject; |
||
36 | use \HOWI3\libhowi\Filesystem\php7\TraitForFileSystem; |
||
37 | use \HOWI3\libhowi\Filesystem\php7\TraitForSharedMethods; |
||
38 | |||
39 | View Code Duplication | class Filesystem extends AbstractFilesystem implements FilesystemInterface, SharedMethodsInterface |
|
40 | { |
||
41 | use TraitForResponse; |
||
42 | use TraitForFileSystem; |
||
43 | use TraitForSharedMethods; |
||
44 | |||
45 | /** |
||
46 | * |
||
47 | * {@inheritDoc} |
||
48 | * |
||
49 | */ |
||
50 | 241 | public function __construct($setCwd = false) |
|
51 | { |
||
52 | 241 | $this->debug(801); |
|
53 | 241 | $this->setStatus(true); |
|
54 | 241 | if (! $this->setCwd($setCwd)) { |
|
55 | 1 | $append = error_get_last(); |
|
56 | 1 | $this->warning(500, $append['message']); |
|
57 | } |
||
58 | |||
59 | 241 | $this->tmp()->setTmp(); |
|
60 | 241 | } |
|
61 | |||
62 | /** |
||
63 | * |
||
64 | * {@inheritDoc} |
||
65 | * |
||
66 | */ |
||
67 | 54 | public function dir($directory = false, $dirname = false, $recursive = true, $mode = false, $context = false) |
|
68 | { |
||
69 | 54 | if (empty($directory)) { |
|
70 | 1 | return false; |
|
71 | } |
||
72 | // /////////// |
||
73 | 53 | $this->debug(807); |
|
74 | 53 | if (array_key_exists($directory, $this->dirkeys) && |
|
75 | 53 | array_key_exists($this->dirkeys[$directory], $this->dirs) && |
|
76 | 53 | is_object($this->dirs[$this->dirkeys[$directory]])) { |
|
77 | 46 | $response = $this->dirs[$this->dirkeys[$directory]]; |
|
78 | 46 | $this->response = $this->dirs[$this->dirkeys[$directory]]->response(); |
|
79 | 53 | } elseif (! empty($directory) && ! empty($dirname)) { |
|
80 | |||
81 | 53 | $dir = $this->makeAbsolute($dirname . DIRECTORY_SEPARATOR . $directory); |
|
82 | 53 | $HID = md5($dir); |
|
83 | 53 | $this->dirkeys[$directory] = $HID; |
|
84 | 53 | $this->dirs[$HID] = $this->isDir($dir) ? new DirectoryTreeObject($dir, |
|
85 | 53 | DirectoryTreeObject::SKIP_DOTS) : new DirectoryPlaceholderObject($dir, $recursive, $mode, |
|
86 | 6 | $context, $this->getLogFile(), $this->getLogLevel(), $this->getUID(), $this->getUsername()); |
|
87 | |||
88 | 53 | if ($this->dirs[$HID] instanceof DirectoryPlaceholderObject) { |
|
89 | 6 | $this->setStatus($this->dirs[$HID]->getStatus()); |
|
90 | 6 | $this->setCode($this->dirs[$HID]->getCode()); |
|
91 | } |
||
92 | |||
93 | 53 | if ($this->dirs[$HID] instanceof DirectoryTreeObject) { |
|
94 | 49 | $this->dirs[$HID]->setFileClass('\HOWI3\libhowi\Filesystem\php7\Objects\FileObject'); |
|
95 | 49 | $this->dirs[$HID]->setInfoClass('\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject'); |
|
96 | 49 | $this->dirs[$HID]->setLogFile($this->getLogFile()); |
|
97 | 49 | $this->dirs[$HID]->setLogLevel($this->getLogLevel()); |
|
98 | 49 | $this->dirs[$HID]->setUID($this->getUID()); |
|
99 | 49 | $this->dirs[$HID]->setUsername($this->getUsername()); |
|
100 | |||
101 | 49 | $this->response->setStatus(true); |
|
102 | } else { |
||
103 | |||
104 | /* We don't need DirectoryPlaceholderObject anymore for this directory */ |
||
105 | 6 | if ($this->isDir($dir)) { |
|
106 | |||
107 | 5 | $this->dirs[$HID] = new DirectoryTreeObject($dir, DirectoryTreeObject::SKIP_DOTS); |
|
108 | 5 | $this->dirs[$HID]->setFileClass('\HOWI3\libhowi\Filesystem\php7\Objects\FileObject'); |
|
109 | 5 | $this->dirs[$HID]->setInfoClass('\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject'); |
|
110 | 5 | $this->dirs[$HID]->setLogFile($this->getLogFile()); |
|
111 | 5 | $this->dirs[$HID]->setLogLevel($this->getLogLevel()); |
|
112 | 5 | $this->dirs[$HID]->setUID($this->getUID()); |
|
113 | 5 | $this->dirs[$HID]->setUsername($this->getUsername()); |
|
114 | } |
||
115 | } |
||
116 | |||
117 | 53 | $response = $this->dirs[$HID]; |
|
118 | } |
||
119 | 53 | return $response; |
|
120 | } |
||
121 | |||
122 | /** |
||
123 | * |
||
124 | * {@inheritDoc} |
||
125 | * |
||
126 | */ |
||
127 | 60 | public function file($filename = false, $dirname = false, $data = '', $flags = FILE_APPEND, $context = null) |
|
0 ignored issues
–
show
|
|||
128 | { |
||
129 | 60 | if (! empty($filename) && array_key_exists($filename, $this->files) && |
|
130 | 60 | is_object($this->files[$filename])) |
|
131 | 57 | return $this->files[$filename]; |
|
132 | |||
133 | 60 | $this->debug(808); |
|
134 | 60 | if (empty($filename)) { |
|
135 | 1 | $this->notice(601); |
|
136 | 1 | return false; |
|
137 | } |
||
138 | |||
139 | 60 | $dirname = empty($dirname) ? $this->getCwd() : $this->makeAbsolute($dirname); |
|
140 | 60 | $real = $dirname . DIRECTORY_SEPARATOR . $filename; |
|
141 | 60 | $real = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $real); |
|
142 | |||
143 | 60 | if (! $this->exists($real) && ! $this->isWritable(dirname($real))) { |
|
144 | 1 | $this->warning(503, $real); |
|
145 | 1 | return false; |
|
146 | 60 | } elseif (! $this->exists($real) && $this->isWritable(dirname($real))) { |
|
147 | 4 | $result = empty($context) || ! is_resource($context) ? file_put_contents($real, $data, $flags) : file_put_contents( |
|
148 | $real, $data, $flags, $context); |
||
149 | 4 | $result = $result !== false ? $this->info(703, $real) : $this->warning(504, $real); |
|
150 | } |
||
151 | |||
152 | 60 | if ($this->exists($real)) { |
|
153 | 60 | $this->files[$filename] = new FileObject($real, 'r+'); |
|
154 | 60 | $this->files[$filename]->setFileClass('\HOWI3\libhowi\Filesystem\php7\Objects\FileObject'); |
|
155 | 60 | $this->files[$filename]->setInfoClass("\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject"); |
|
156 | 60 | $result = $this->files[$filename]; |
|
157 | } |
||
158 | |||
159 | 60 | return $result; |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * |
||
164 | * {@inheritDoc} |
||
165 | * |
||
166 | */ |
||
167 | 33 | public function infoObject($basename = false, $directory = false) |
|
168 | { |
||
169 | 33 | if (! empty($basename) && array_key_exists($basename, $this->infos) && is_object( |
|
170 | 33 | $this->infos[$basename])) |
|
171 | 32 | return $this->infos[$basename]; |
|
172 | |||
173 | 33 | $this->debug(809); |
|
174 | 33 | if (empty($basename)) { |
|
175 | 1 | $this->notice(602); |
|
176 | 1 | return false; |
|
177 | } |
||
178 | |||
179 | 33 | $dirname = empty($directory) ? $this->getCwd() : $this->makeAbsolute($directory); |
|
180 | 33 | $real = $dirname . DIRECTORY_SEPARATOR . $basename; |
|
181 | 33 | $real = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $real); |
|
182 | |||
183 | |||
184 | 33 | if (! $this->exists($real) && ! $this->isReadable($real)) { |
|
185 | 1 | $this->warning(504, $real); |
|
186 | 1 | $result = false; |
|
187 | 33 | } elseif ($this->exists($real)) { |
|
188 | 33 | $this->infos[$basename] = new InfoObject($real); |
|
189 | 33 | $this->infos[$basename]->setFileClass('\HOWI3\libhowi\Filesystem\php7\Objects\FileObject'); |
|
190 | 33 | $this->infos[$basename]->setInfoClass("\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject"); |
|
191 | 33 | $result = $this->infos[$basename]; |
|
192 | } |
||
193 | 33 | return $result; |
|
194 | } |
||
195 | |||
196 | /** |
||
197 | * |
||
198 | * {@inheritDoc} |
||
199 | * |
||
200 | */ |
||
201 | 241 | public function tmp($keyword = 'tmp') |
|
202 | { |
||
203 | 241 | if (array_key_exists($keyword, $this->tmp) && is_object($this->tmp[$keyword]) && |
|
204 | 241 | $this->tmp[$keyword] instanceof \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\TmpInterface) { |
|
205 | 4 | return $this->tmp[$keyword]; |
|
206 | } else { |
||
207 | 241 | $this->tmp[$keyword] = new TmpObject(); |
|
208 | 241 | return $this->tmp[$keyword]; |
|
209 | } |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * |
||
214 | * {@inheritDoc} |
||
215 | * |
||
216 | */ |
||
217 | 8 | public function link($keyword = 'link') |
|
218 | { |
||
219 | 8 | if (array_key_exists($keyword, $this->link) && is_object($this->link[$keyword]) && |
|
220 | 8 | $this->link[$keyword] instanceof \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\LinkInterface) { |
|
221 | 5 | return $this->link[$keyword]; |
|
222 | } else { |
||
223 | 8 | $this->link[$keyword] = new LinkObject(); |
|
224 | 8 | return $this->link[$keyword]; |
|
225 | } |
||
226 | } |
||
227 | } |
||
228 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.