| @@ 39-229 (lines=191) @@ | ||
| 36 | use \HOWI3\libhowi\Filesystem\php5\TraitForFileSystem; |
|
| 37 | use \HOWI3\libhowi\Filesystem\php5\TraitForSharedMethods; |
|
| 38 | ||
| 39 | 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 | public function __construct($setCwd = false) |
|
| 51 | { |
|
| 52 | $this->debug(801); |
|
| 53 | $this->setStatus(true); |
|
| 54 | if (! $this->setCwd($setCwd)) { |
|
| 55 | $append = error_get_last(); |
|
| 56 | $this->warning(500, $append['message']); |
|
| 57 | } |
|
| 58 | ||
| 59 | $this->tmp()->setTmp(); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * |
|
| 64 | * {@inheritDoc} |
|
| 65 | * |
|
| 66 | */ |
|
| 67 | public function dir($directory = false, $dirname = false, $recursive = true, $mode = false, $context = false) |
|
| 68 | { |
|
| 69 | $response = null; |
|
| 70 | if (empty($directory)) { |
|
| 71 | return false; |
|
| 72 | } |
|
| 73 | // /////////// |
|
| 74 | $this->debug(807); |
|
| 75 | if (array_key_exists($directory, $this->dirkeys) && |
|
| 76 | array_key_exists($this->dirkeys[$directory], $this->dirs) && |
|
| 77 | is_object($this->dirs[$this->dirkeys[$directory]])) { |
|
| 78 | $response = $this->dirs[$this->dirkeys[$directory]]; |
|
| 79 | $this->response = $this->dirs[$this->dirkeys[$directory]]->response(); |
|
| 80 | } elseif (! empty($directory) && ! empty($dirname)) { |
|
| 81 | ||
| 82 | $dir = $this->makeAbsolute($dirname . DIRECTORY_SEPARATOR . $directory); |
|
| 83 | $HID = md5($dir); |
|
| 84 | $this->dirkeys[$directory] = $HID; |
|
| 85 | $this->dirs[$HID] = $this->isDir($dir) ? new DirectoryTreeObject($dir, |
|
| 86 | DirectoryTreeObject::SKIP_DOTS) : new DirectoryPlaceholderObject($dir, $recursive, $mode, |
|
| 87 | $context, $this->getLogFile(), $this->getLogLevel(), $this->getUID(), $this->getUsername()); |
|
| 88 | ||
| 89 | if ($this->dirs[$HID] instanceof DirectoryPlaceholderObject) { |
|
| 90 | $this->setStatus($this->dirs[$HID]->getStatus()); |
|
| 91 | $this->setCode($this->dirs[$HID]->getCode()); |
|
| 92 | } |
|
| 93 | ||
| 94 | if ($this->dirs[$HID] instanceof DirectoryTreeObject) { |
|
| 95 | $this->dirs[$HID]->setFileClass('\HOWI3\libhowi\Filesystem\php5\Objects\FileObject'); |
|
| 96 | $this->dirs[$HID]->setInfoClass('\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject'); |
|
| 97 | $this->dirs[$HID]->setLogFile($this->getLogFile()); |
|
| 98 | $this->dirs[$HID]->setLogLevel($this->getLogLevel()); |
|
| 99 | $this->dirs[$HID]->setUID($this->getUID()); |
|
| 100 | $this->dirs[$HID]->setUsername($this->getUsername()); |
|
| 101 | ||
| 102 | $this->response->setStatus(true); |
|
| 103 | } else { |
|
| 104 | ||
| 105 | /* We don't need DirectoryPlaceholderObject anymore for this directory */ |
|
| 106 | if ($this->isDir($dir)) { |
|
| 107 | ||
| 108 | $this->dirs[$HID] = new DirectoryTreeObject($dir, DirectoryTreeObject::SKIP_DOTS); |
|
| 109 | $this->dirs[$HID]->setFileClass('\HOWI3\libhowi\Filesystem\php5\Objects\FileObject'); |
|
| 110 | $this->dirs[$HID]->setInfoClass('\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject'); |
|
| 111 | $this->dirs[$HID]->setLogFile($this->getLogFile()); |
|
| 112 | $this->dirs[$HID]->setLogLevel($this->getLogLevel()); |
|
| 113 | $this->dirs[$HID]->setUID($this->getUID()); |
|
| 114 | $this->dirs[$HID]->setUsername($this->getUsername()); |
|
| 115 | } |
|
| 116 | } |
|
| 117 | ||
| 118 | $response = $this->dirs[$HID]; |
|
| 119 | } |
|
| 120 | ||
| 121 | return $response; |
|
| 122 | } |
|
| 123 | ||
| 124 | /** |
|
| 125 | * |
|
| 126 | * {@inheritDoc} |
|
| 127 | * |
|
| 128 | */ |
|
| 129 | public function file($filename = false, $dirname = false, $data = '', $flags = FILE_APPEND, $context = null) |
|
| 130 | { |
|
| 131 | if (! empty($filename) && array_key_exists($filename, $this->files) && |
|
| 132 | is_object($this->files[$filename])) |
|
| 133 | return $this->files[$filename]; |
|
| 134 | ||
| 135 | $this->debug(808); |
|
| 136 | if (empty($filename)) { |
|
| 137 | $this->notice(601); |
|
| 138 | return false; |
|
| 139 | } |
|
| 140 | ||
| 141 | $dirname = empty($dirname) ? $this->getCwd() : $this->makeAbsolute($dirname); |
|
| 142 | $real = $dirname . DIRECTORY_SEPARATOR . $filename; |
|
| 143 | $real = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $real); |
|
| 144 | ||
| 145 | if (! $this->exists($real) && ! $this->isWritable(dirname($real))) { |
|
| 146 | $this->warning(503, $real); |
|
| 147 | return false; |
|
| 148 | } elseif (! $this->exists($real) && $this->isWritable(dirname($real))) { |
|
| 149 | $result = empty($context) || ! is_resource($context) ? file_put_contents($real, $data, $flags) : file_put_contents( |
|
| 150 | $real, $data, $flags, $context); |
|
| 151 | $result = $result !== false ? $this->info(703, $real) : $this->warning(504, $real); |
|
| 152 | } |
|
| 153 | ||
| 154 | if ($this->exists($real)) { |
|
| 155 | $this->files[$filename] = new FileObject($real, 'r+'); |
|
| 156 | $this->files[$filename]->setFileClass('\HOWI3\libhowi\Filesystem\php5\Objects\FileObject'); |
|
| 157 | $this->files[$filename]->setInfoClass("\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject"); |
|
| 158 | $result = $this->files[$filename]; |
|
| 159 | } |
|
| 160 | ||
| 161 | return $result; |
|
| 162 | } |
|
| 163 | ||
| 164 | /** |
|
| 165 | * |
|
| 166 | * {@inheritDoc} |
|
| 167 | * |
|
| 168 | */ |
|
| 169 | public function infoObject($basename = false, $directory = false) |
|
| 170 | { |
|
| 171 | if (! empty($basename) && array_key_exists($basename, $this->infos) && is_object( |
|
| 172 | $this->infos[$basename])) |
|
| 173 | return $this->infos[$basename]; |
|
| 174 | ||
| 175 | $this->debug(809); |
|
| 176 | if (empty($basename)) { |
|
| 177 | $this->notice(602); |
|
| 178 | return false; |
|
| 179 | } |
|
| 180 | ||
| 181 | $dirname = empty($directory) ? $this->getCwd() : $this->makeAbsolute($directory); |
|
| 182 | $real = $dirname . DIRECTORY_SEPARATOR . $basename; |
|
| 183 | $real = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $real); |
|
| 184 | ||
| 185 | ||
| 186 | if (! $this->exists($real) && ! $this->isReadable($real)) { |
|
| 187 | $this->warning(504, $real); |
|
| 188 | $result = false; |
|
| 189 | } elseif ($this->exists($real)) { |
|
| 190 | $this->infos[$basename] = new InfoObject($real); |
|
| 191 | $this->infos[$basename]->setFileClass('\HOWI3\libhowi\Filesystem\php5\Objects\FileObject'); |
|
| 192 | $this->infos[$basename]->setInfoClass("\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject"); |
|
| 193 | $result = $this->infos[$basename]; |
|
| 194 | } |
|
| 195 | return $result; |
|
| 196 | } |
|
| 197 | ||
| 198 | /** |
|
| 199 | * |
|
| 200 | * {@inheritDoc} |
|
| 201 | * |
|
| 202 | */ |
|
| 203 | public function tmp($keyword = 'tmp') |
|
| 204 | { |
|
| 205 | if (array_key_exists($keyword, $this->tmp) && is_object($this->tmp[$keyword]) && |
|
| 206 | $this->tmp[$keyword] instanceof \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\TmpInterface) { |
|
| 207 | return $this->tmp[$keyword]; |
|
| 208 | } else { |
|
| 209 | $this->tmp[$keyword] = new TmpObject(); |
|
| 210 | return $this->tmp[$keyword]; |
|
| 211 | } |
|
| 212 | } |
|
| 213 | ||
| 214 | /** |
|
| 215 | * |
|
| 216 | * {@inheritDoc} |
|
| 217 | * |
|
| 218 | */ |
|
| 219 | public function link($keyword = 'link') |
|
| 220 | { |
|
| 221 | if (array_key_exists($keyword, $this->link) && is_object($this->link[$keyword]) && |
|
| 222 | $this->link[$keyword] instanceof \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\LinkInterface) { |
|
| 223 | return $this->link[$keyword]; |
|
| 224 | } else { |
|
| 225 | $this->link[$keyword] = new LinkObject(); |
|
| 226 | return $this->link[$keyword]; |
|
| 227 | } |
|
| 228 | } |
|
| 229 | } |
|
| 230 | ||
| @@ 39-227 (lines=189) @@ | ||
| 36 | use \HOWI3\libhowi\Filesystem\php7\TraitForFileSystem; |
|
| 37 | use \HOWI3\libhowi\Filesystem\php7\TraitForSharedMethods; |
|
| 38 | ||
| 39 | 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 | public function __construct($setCwd = false) |
|
| 51 | { |
|
| 52 | $this->debug(801); |
|
| 53 | $this->setStatus(true); |
|
| 54 | if (! $this->setCwd($setCwd)) { |
|
| 55 | $append = error_get_last(); |
|
| 56 | $this->warning(500, $append['message']); |
|
| 57 | } |
|
| 58 | ||
| 59 | $this->tmp()->setTmp(); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * |
|
| 64 | * {@inheritDoc} |
|
| 65 | * |
|
| 66 | */ |
|
| 67 | public function dir($directory = false, $dirname = false, $recursive = true, $mode = false, $context = false) |
|
| 68 | { |
|
| 69 | if (empty($directory)) { |
|
| 70 | return false; |
|
| 71 | } |
|
| 72 | // /////////// |
|
| 73 | $this->debug(807); |
|
| 74 | if (array_key_exists($directory, $this->dirkeys) && |
|
| 75 | array_key_exists($this->dirkeys[$directory], $this->dirs) && |
|
| 76 | is_object($this->dirs[$this->dirkeys[$directory]])) { |
|
| 77 | $response = $this->dirs[$this->dirkeys[$directory]]; |
|
| 78 | $this->response = $this->dirs[$this->dirkeys[$directory]]->response(); |
|
| 79 | } elseif (! empty($directory) && ! empty($dirname)) { |
|
| 80 | ||
| 81 | $dir = $this->makeAbsolute($dirname . DIRECTORY_SEPARATOR . $directory); |
|
| 82 | $HID = md5($dir); |
|
| 83 | $this->dirkeys[$directory] = $HID; |
|
| 84 | $this->dirs[$HID] = $this->isDir($dir) ? new DirectoryTreeObject($dir, |
|
| 85 | DirectoryTreeObject::SKIP_DOTS) : new DirectoryPlaceholderObject($dir, $recursive, $mode, |
|
| 86 | $context, $this->getLogFile(), $this->getLogLevel(), $this->getUID(), $this->getUsername()); |
|
| 87 | ||
| 88 | if ($this->dirs[$HID] instanceof DirectoryPlaceholderObject) { |
|
| 89 | $this->setStatus($this->dirs[$HID]->getStatus()); |
|
| 90 | $this->setCode($this->dirs[$HID]->getCode()); |
|
| 91 | } |
|
| 92 | ||
| 93 | if ($this->dirs[$HID] instanceof DirectoryTreeObject) { |
|
| 94 | $this->dirs[$HID]->setFileClass('\HOWI3\libhowi\Filesystem\php7\Objects\FileObject'); |
|
| 95 | $this->dirs[$HID]->setInfoClass('\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject'); |
|
| 96 | $this->dirs[$HID]->setLogFile($this->getLogFile()); |
|
| 97 | $this->dirs[$HID]->setLogLevel($this->getLogLevel()); |
|
| 98 | $this->dirs[$HID]->setUID($this->getUID()); |
|
| 99 | $this->dirs[$HID]->setUsername($this->getUsername()); |
|
| 100 | ||
| 101 | $this->response->setStatus(true); |
|
| 102 | } else { |
|
| 103 | ||
| 104 | /* We don't need DirectoryPlaceholderObject anymore for this directory */ |
|
| 105 | if ($this->isDir($dir)) { |
|
| 106 | ||
| 107 | $this->dirs[$HID] = new DirectoryTreeObject($dir, DirectoryTreeObject::SKIP_DOTS); |
|
| 108 | $this->dirs[$HID]->setFileClass('\HOWI3\libhowi\Filesystem\php7\Objects\FileObject'); |
|
| 109 | $this->dirs[$HID]->setInfoClass('\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject'); |
|
| 110 | $this->dirs[$HID]->setLogFile($this->getLogFile()); |
|
| 111 | $this->dirs[$HID]->setLogLevel($this->getLogLevel()); |
|
| 112 | $this->dirs[$HID]->setUID($this->getUID()); |
|
| 113 | $this->dirs[$HID]->setUsername($this->getUsername()); |
|
| 114 | } |
|
| 115 | } |
|
| 116 | ||
| 117 | $response = $this->dirs[$HID]; |
|
| 118 | } |
|
| 119 | return $response; |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * |
|
| 124 | * {@inheritDoc} |
|
| 125 | * |
|
| 126 | */ |
|
| 127 | public function file($filename = false, $dirname = false, $data = '', $flags = FILE_APPEND, $context = null) |
|
| 128 | { |
|
| 129 | if (! empty($filename) && array_key_exists($filename, $this->files) && |
|
| 130 | is_object($this->files[$filename])) |
|
| 131 | return $this->files[$filename]; |
|
| 132 | ||
| 133 | $this->debug(808); |
|
| 134 | if (empty($filename)) { |
|
| 135 | $this->notice(601); |
|
| 136 | return false; |
|
| 137 | } |
|
| 138 | ||
| 139 | $dirname = empty($dirname) ? $this->getCwd() : $this->makeAbsolute($dirname); |
|
| 140 | $real = $dirname . DIRECTORY_SEPARATOR . $filename; |
|
| 141 | $real = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $real); |
|
| 142 | ||
| 143 | if (! $this->exists($real) && ! $this->isWritable(dirname($real))) { |
|
| 144 | $this->warning(503, $real); |
|
| 145 | return false; |
|
| 146 | } elseif (! $this->exists($real) && $this->isWritable(dirname($real))) { |
|
| 147 | $result = empty($context) || ! is_resource($context) ? file_put_contents($real, $data, $flags) : file_put_contents( |
|
| 148 | $real, $data, $flags, $context); |
|
| 149 | $result = $result !== false ? $this->info(703, $real) : $this->warning(504, $real); |
|
| 150 | } |
|
| 151 | ||
| 152 | if ($this->exists($real)) { |
|
| 153 | $this->files[$filename] = new FileObject($real, 'r+'); |
|
| 154 | $this->files[$filename]->setFileClass('\HOWI3\libhowi\Filesystem\php7\Objects\FileObject'); |
|
| 155 | $this->files[$filename]->setInfoClass("\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject"); |
|
| 156 | $result = $this->files[$filename]; |
|
| 157 | } |
|
| 158 | ||
| 159 | return $result; |
|
| 160 | } |
|
| 161 | ||
| 162 | /** |
|
| 163 | * |
|
| 164 | * {@inheritDoc} |
|
| 165 | * |
|
| 166 | */ |
|
| 167 | public function infoObject($basename = false, $directory = false) |
|
| 168 | { |
|
| 169 | if (! empty($basename) && array_key_exists($basename, $this->infos) && is_object( |
|
| 170 | $this->infos[$basename])) |
|
| 171 | return $this->infos[$basename]; |
|
| 172 | ||
| 173 | $this->debug(809); |
|
| 174 | if (empty($basename)) { |
|
| 175 | $this->notice(602); |
|
| 176 | return false; |
|
| 177 | } |
|
| 178 | ||
| 179 | $dirname = empty($directory) ? $this->getCwd() : $this->makeAbsolute($directory); |
|
| 180 | $real = $dirname . DIRECTORY_SEPARATOR . $basename; |
|
| 181 | $real = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $real); |
|
| 182 | ||
| 183 | ||
| 184 | if (! $this->exists($real) && ! $this->isReadable($real)) { |
|
| 185 | $this->warning(504, $real); |
|
| 186 | $result = false; |
|
| 187 | } elseif ($this->exists($real)) { |
|
| 188 | $this->infos[$basename] = new InfoObject($real); |
|
| 189 | $this->infos[$basename]->setFileClass('\HOWI3\libhowi\Filesystem\php7\Objects\FileObject'); |
|
| 190 | $this->infos[$basename]->setInfoClass("\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject"); |
|
| 191 | $result = $this->infos[$basename]; |
|
| 192 | } |
|
| 193 | return $result; |
|
| 194 | } |
|
| 195 | ||
| 196 | /** |
|
| 197 | * |
|
| 198 | * {@inheritDoc} |
|
| 199 | * |
|
| 200 | */ |
|
| 201 | public function tmp($keyword = 'tmp') |
|
| 202 | { |
|
| 203 | if (array_key_exists($keyword, $this->tmp) && is_object($this->tmp[$keyword]) && |
|
| 204 | $this->tmp[$keyword] instanceof \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\TmpInterface) { |
|
| 205 | return $this->tmp[$keyword]; |
|
| 206 | } else { |
|
| 207 | $this->tmp[$keyword] = new TmpObject(); |
|
| 208 | return $this->tmp[$keyword]; |
|
| 209 | } |
|
| 210 | } |
|
| 211 | ||
| 212 | /** |
|
| 213 | * |
|
| 214 | * {@inheritDoc} |
|
| 215 | * |
|
| 216 | */ |
|
| 217 | public function link($keyword = 'link') |
|
| 218 | { |
|
| 219 | if (array_key_exists($keyword, $this->link) && is_object($this->link[$keyword]) && |
|
| 220 | $this->link[$keyword] instanceof \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\LinkInterface) { |
|
| 221 | return $this->link[$keyword]; |
|
| 222 | } else { |
|
| 223 | $this->link[$keyword] = new LinkObject(); |
|
| 224 | return $this->link[$keyword]; |
|
| 225 | } |
|
| 226 | } |
|
| 227 | } |
|
| 228 | ||