@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | private function _pathinfo($file, $mode) |
| 67 | 67 | { |
| 68 | - if (!is_scalar($file) && !is_scalar($mode)) { |
|
| 68 | + if ( ! is_scalar($file) && ! is_scalar($mode)) { |
|
| 69 | 69 | $file = $mode = ''; |
| 70 | 70 | } |
| 71 | - $flag = !(empty($file) || empty($mode)); |
|
| 71 | + $flag = ! (empty($file) || empty($mode)); |
|
| 72 | 72 | $f = MODX_BASE_PATH . $this->relativePath($file); |
| 73 | - if ($flag && !isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) { |
|
| 73 | + if ($flag && ! isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) { |
|
| 74 | 74 | $this->_fileInfo[$f] = pathinfo($f); |
| 75 | 75 | } |
| 76 | 76 | $out = $flag && isset($this->_fileInfo[$f][$mode]) ? $this->_fileInfo[$f][$mode] : ''; |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | public function takeFileExt($file, $lower = true) |
| 114 | 114 | { |
| 115 | 115 | $str = $this->_pathinfo($file, 'extension'); |
| 116 | - if($lower){ |
|
| 116 | + if ($lower) { |
|
| 117 | 117 | $str = strtolower($str); |
| 118 | 118 | } |
| 119 | 119 | return $str; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | { |
| 128 | 128 | $f = is_scalar($file) ? MODX_BASE_PATH . $this->relativePath($file) : ''; |
| 129 | 129 | |
| 130 | - return (!empty($f) && is_file($f) && is_readable($f)); |
|
| 130 | + return ( ! empty($f) && is_file($f) && is_readable($f)); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | { |
| 139 | 139 | $f = is_scalar($path) ? $this->relativePath($path) : ''; |
| 140 | 140 | |
| 141 | - return (!empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f)); |
|
| 141 | + return ( ! empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f)); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function makeDir($path, $perm = 0755) |
| 228 | 228 | { |
| 229 | - if (!$this->checkDir($path)) { |
|
| 229 | + if ( ! $this->checkDir($path)) { |
|
| 230 | 230 | $path = MODX_BASE_PATH . $this->relativePath($path); |
| 231 | 231 | $flag = mkdir($path, $this->toOct($perm), true); |
| 232 | 232 | } else { |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | $owner = MODX_BASE_PATH; |
| 292 | 292 | } |
| 293 | 293 | $path = str_replace('\\', '/', $path); |
| 294 | - if (!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/", $path)) { |
|
| 294 | + if ( ! (empty($path) || ! is_scalar($path)) && ! preg_match("/^http(s)?:\/\/\w+/", $path)) { |
|
| 295 | 295 | $path = trim(preg_replace("#^" . preg_quote($owner) . "#", '', $path), DIRECTORY_SEPARATOR); |
| 296 | 296 | } else { |
| 297 | 297 | $path = ''; |
@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | * Class FS |
| 5 | 5 | * @package Helpers |
| 6 | 6 | */ |
| 7 | -class FS |
|
| 8 | -{ |
|
| 7 | +class FS |
|
| 8 | +{
|
|
| 9 | 9 | /** |
| 10 | 10 | * @var FS cached reference to singleton instance |
| 11 | 11 | */ |
@@ -21,9 +21,9 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @return self |
| 23 | 23 | */ |
| 24 | - public static function getInstance() |
|
| 25 | - { |
|
| 26 | - if (null === self::$instance) { |
|
| 24 | + public static function getInstance() |
|
| 25 | + {
|
|
| 26 | + if (null === self::$instance) {
|
|
| 27 | 27 | self::$instance = new self(); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | * is not allowed to call from outside: private! |
| 35 | 35 | * |
| 36 | 36 | */ |
| 37 | - private function __construct() |
|
| 38 | - { |
|
| 37 | + private function __construct() |
|
| 38 | + {
|
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return void |
| 45 | 45 | */ |
| 46 | - private function __clone() |
|
| 47 | - { |
|
| 46 | + private function __clone() |
|
| 47 | + {
|
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @return void |
| 54 | 54 | */ |
| 55 | - private function __wakeup() |
|
| 56 | - { |
|
| 55 | + private function __wakeup() |
|
| 56 | + {
|
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | * @param string $file ключ |
| 64 | 64 | * @return string информация из pathinfo о обрабатываемом файле input |
| 65 | 65 | */ |
| 66 | - private function _pathinfo($file, $mode) |
|
| 67 | - { |
|
| 68 | - if (!is_scalar($file) && !is_scalar($mode)) { |
|
| 66 | + private function _pathinfo($file, $mode) |
|
| 67 | + {
|
|
| 68 | + if (!is_scalar($file) && !is_scalar($mode)) {
|
|
| 69 | 69 | $file = $mode = ''; |
| 70 | 70 | } |
| 71 | 71 | $flag = !(empty($file) || empty($mode)); |
| 72 | 72 | $f = MODX_BASE_PATH . $this->relativePath($file); |
| 73 | - if ($flag && !isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) { |
|
| 73 | + if ($flag && !isset($this->_fileInfo[$f], $this->_fileInfo[$f][$mode])) {
|
|
| 74 | 74 | $this->_fileInfo[$f] = pathinfo($f); |
| 75 | 75 | } |
| 76 | 76 | $out = $flag && isset($this->_fileInfo[$f][$mode]) ? $this->_fileInfo[$f][$mode] : ''; |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | * @param $file |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | - public function takeFileDir($file) |
|
| 86 | - { |
|
| 85 | + public function takeFileDir($file) |
|
| 86 | + {
|
|
| 87 | 87 | return $this->_pathinfo($file, 'dirname'); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -91,8 +91,9 @@ discard block |
||
| 91 | 91 | * @param $file |
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | - public function takeFileBasename($file) |
|
| 95 | - { //file name with extension |
|
| 94 | + public function takeFileBasename($file) |
|
| 95 | + {
|
|
| 96 | +//file name with extension |
|
| 96 | 97 | return $this->_pathinfo($file, 'basename'); |
| 97 | 98 | } |
| 98 | 99 | |
@@ -100,8 +101,8 @@ discard block |
||
| 100 | 101 | * @param $file |
| 101 | 102 | * @return string |
| 102 | 103 | */ |
| 103 | - public function takeFileName($file) |
|
| 104 | - { |
|
| 104 | + public function takeFileName($file) |
|
| 105 | + {
|
|
| 105 | 106 | return $this->_pathinfo($file, 'filename'); |
| 106 | 107 | } |
| 107 | 108 | |
@@ -110,10 +111,10 @@ discard block |
||
| 110 | 111 | * @param bool $lower |
| 111 | 112 | * @return string |
| 112 | 113 | */ |
| 113 | - public function takeFileExt($file, $lower = true) |
|
| 114 | - { |
|
| 114 | + public function takeFileExt($file, $lower = true) |
|
| 115 | + {
|
|
| 115 | 116 | $str = $this->_pathinfo($file, 'extension'); |
| 116 | - if($lower){ |
|
| 117 | + if($lower) {
|
|
| 117 | 118 | $str = strtolower($str); |
| 118 | 119 | } |
| 119 | 120 | return $str; |
@@ -123,8 +124,8 @@ discard block |
||
| 123 | 124 | * @param $file |
| 124 | 125 | * @return bool |
| 125 | 126 | */ |
| 126 | - public function checkFile($file) |
|
| 127 | - { |
|
| 127 | + public function checkFile($file) |
|
| 128 | + {
|
|
| 128 | 129 | $f = is_scalar($file) ? MODX_BASE_PATH . $this->relativePath($file) : ''; |
| 129 | 130 | |
| 130 | 131 | return (!empty($f) && is_file($f) && is_readable($f)); |
@@ -134,8 +135,8 @@ discard block |
||
| 134 | 135 | * @param $path |
| 135 | 136 | * @return bool |
| 136 | 137 | */ |
| 137 | - public function checkDir($path) |
|
| 138 | - { |
|
| 138 | + public function checkDir($path) |
|
| 139 | + {
|
|
| 139 | 140 | $f = is_scalar($path) ? $this->relativePath($path) : ''; |
| 140 | 141 | |
| 141 | 142 | return (!empty($f) && is_dir(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f)); |
@@ -146,13 +147,13 @@ discard block |
||
| 146 | 147 | * @param bool $format |
| 147 | 148 | * @return int|string |
| 148 | 149 | */ |
| 149 | - public function fileSize($file, $format = false) |
|
| 150 | - { |
|
| 150 | + public function fileSize($file, $format = false) |
|
| 151 | + {
|
|
| 151 | 152 | $out = 0; |
| 152 | - if ($this->checkFile($file)) { |
|
| 153 | + if ($this->checkFile($file)) {
|
|
| 153 | 154 | $out = filesize(MODX_BASE_PATH . $this->relativePath($file)); |
| 154 | 155 | } |
| 155 | - if ($format) { |
|
| 156 | + if ($format) {
|
|
| 156 | 157 | $types = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); |
| 157 | 158 | $size = $out > 0 ? floor(log($out, 1024)) : 0; |
| 158 | 159 | $out = number_format($out / pow(1024, $size), 2, '.', ',') . ' ' . $types[$size]; |
@@ -171,17 +172,17 @@ discard block |
||
| 171 | 172 | * @param string $file Имя файла |
| 172 | 173 | * @return null|string MIME тип файла |
| 173 | 174 | */ |
| 174 | - public function takeFileMIME($file) |
|
| 175 | - { |
|
| 175 | + public function takeFileMIME($file) |
|
| 176 | + {
|
|
| 176 | 177 | $out = null; |
| 177 | 178 | $path = $this->relativePath($file); |
| 178 | - if ($this->checkFile($path)) { |
|
| 179 | + if ($this->checkFile($path)) {
|
|
| 179 | 180 | $fname = MODX_BASE_PATH . $path; |
| 180 | - switch (true) { |
|
| 181 | + switch (true) {
|
|
| 181 | 182 | /** need fileinfo extension */ |
| 182 | 183 | case (extension_loaded('fileinfo') && class_exists('\finfo')): |
| 183 | 184 | $fi = new \finfo(FILEINFO_MIME_TYPE); |
| 184 | - if ($fi) { |
|
| 185 | + if ($fi) {
|
|
| 185 | 186 | $out = $fi->file($fname); |
| 186 | 187 | } |
| 187 | 188 | break; |
@@ -193,10 +194,10 @@ discard block |
||
| 193 | 194 | * @see: http://www.php.net/manual/ru/function.finfo-open.php#112617 |
| 194 | 195 | */ |
| 195 | 196 | $fh = fopen($fname, 'rb'); |
| 196 | - if ($fh) { |
|
| 197 | + if ($fh) {
|
|
| 197 | 198 | $bytes6 = fread($fh, 6); |
| 198 | 199 | fclose($fh); |
| 199 | - switch (true) { |
|
| 200 | + switch (true) {
|
|
| 200 | 201 | case ($bytes6 === false): |
| 201 | 202 | break; |
| 202 | 203 | case (substr($bytes6, 0, 3) == "\xff\xd8\xff"): |
@@ -224,12 +225,12 @@ discard block |
||
| 224 | 225 | * @param int $perm |
| 225 | 226 | * @return bool |
| 226 | 227 | */ |
| 227 | - public function makeDir($path, $perm = 0755) |
|
| 228 | - { |
|
| 229 | - if (!$this->checkDir($path)) { |
|
| 228 | + public function makeDir($path, $perm = 0755) |
|
| 229 | + {
|
|
| 230 | + if (!$this->checkDir($path)) {
|
|
| 230 | 231 | $path = MODX_BASE_PATH . $this->relativePath($path); |
| 231 | 232 | $flag = mkdir($path, $this->toOct($perm), true); |
| 232 | - } else { |
|
| 233 | + } else {
|
|
| 233 | 234 | $flag = true; |
| 234 | 235 | } |
| 235 | 236 | |
@@ -243,13 +244,13 @@ discard block |
||
| 243 | 244 | * @param string $to получатель |
| 244 | 245 | * @return bool статус копирования |
| 245 | 246 | */ |
| 246 | - public function copyFile($from, $to, $chmod = 0644) |
|
| 247 | - { |
|
| 247 | + public function copyFile($from, $to, $chmod = 0644) |
|
| 248 | + {
|
|
| 248 | 249 | $flag = false; |
| 249 | 250 | $from = MODX_BASE_PATH . $this->relativePath($from); |
| 250 | 251 | $to = MODX_BASE_PATH . $this->relativePath($to); |
| 251 | 252 | $dir = $this->takeFileDir($to); |
| 252 | - if ($this->checkFile($from) && $this->makeDir($dir) && copy($from, $to)) { |
|
| 253 | + if ($this->checkFile($from) && $this->makeDir($dir) && copy($from, $to)) {
|
|
| 253 | 254 | chmod($to, $this->toOct($chmod)); |
| 254 | 255 | $flag = true; |
| 255 | 256 | } |
@@ -264,13 +265,13 @@ discard block |
||
| 264 | 265 | * @param string $to получатель |
| 265 | 266 | * @return bool статус перемещения |
| 266 | 267 | */ |
| 267 | - public function moveFile($from, $to, $chmod = 0644) |
|
| 268 | - { |
|
| 268 | + public function moveFile($from, $to, $chmod = 0644) |
|
| 269 | + {
|
|
| 269 | 270 | $flag = false; |
| 270 | 271 | $from = MODX_BASE_PATH . $this->relativePath($from); |
| 271 | 272 | $to = MODX_BASE_PATH . $this->relativePath($to); |
| 272 | 273 | $dir = $this->takeFileDir($to); |
| 273 | - if ($this->checkFile($from) && $this->makeDir($dir) && rename($from, $to)) { |
|
| 274 | + if ($this->checkFile($from) && $this->makeDir($dir) && rename($from, $to)) {
|
|
| 274 | 275 | chmod($to, $this->toOct($chmod)); |
| 275 | 276 | $flag = true; |
| 276 | 277 | } |
@@ -285,15 +286,15 @@ discard block |
||
| 285 | 286 | * @param string $owner начальный путь который стоит вырезать |
| 286 | 287 | * @return string относительный путь |
| 287 | 288 | */ |
| 288 | - public function relativePath($path, $owner = null) |
|
| 289 | - { |
|
| 290 | - if (is_null($owner)) { |
|
| 289 | + public function relativePath($path, $owner = null) |
|
| 290 | + {
|
|
| 291 | + if (is_null($owner)) {
|
|
| 291 | 292 | $owner = MODX_BASE_PATH; |
| 292 | 293 | } |
| 293 | 294 | $path = str_replace('\\', '/', $path); |
| 294 | - if (!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/", $path)) { |
|
| 295 | + if (!(empty($path) || !is_scalar($path)) && !preg_match("/^http(s)?:\/\/\w+/", $path)) {
|
|
| 295 | 296 | $path = trim(preg_replace("#^" . preg_quote($owner) . "#", '', $path), DIRECTORY_SEPARATOR); |
| 296 | - } else { |
|
| 297 | + } else {
|
|
| 297 | 298 | $path = ''; |
| 298 | 299 | } |
| 299 | 300 | |
@@ -312,8 +313,8 @@ discard block |
||
| 312 | 313 | * @param mixed $chmod строка или число в восьмеричной/десятичной системе счисления |
| 313 | 314 | * @return int число в восьмеричной системе счисления |
| 314 | 315 | */ |
| 315 | - public function toOct($chmod) |
|
| 316 | - { |
|
| 316 | + public function toOct($chmod) |
|
| 317 | + {
|
|
| 317 | 318 | return is_string($chmod) ? octdec($chmod) : $chmod; |
| 318 | 319 | } |
| 319 | 320 | |
@@ -321,15 +322,15 @@ discard block |
||
| 321 | 322 | * @param $dirPath |
| 322 | 323 | * @return bool |
| 323 | 324 | */ |
| 324 | - public function rmDir($dirPath) |
|
| 325 | - { |
|
| 325 | + public function rmDir($dirPath) |
|
| 326 | + {
|
|
| 326 | 327 | $flag = false; |
| 327 | 328 | $path = $_path = MODX_BASE_PATH . $this->relativePath($dirPath); |
| 328 | - if ($this->checkDir($path)) { |
|
| 329 | + if ($this->checkDir($path)) {
|
|
| 329 | 330 | $dirIterator = new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS); |
| 330 | 331 | $dirRecursiveIterator = new \RecursiveIteratorIterator($dirIterator, |
| 331 | 332 | \RecursiveIteratorIterator::CHILD_FIRST); |
| 332 | - foreach ($dirRecursiveIterator as $path) { |
|
| 333 | + foreach ($dirRecursiveIterator as $path) {
|
|
| 333 | 334 | $path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname()); |
| 334 | 335 | } |
| 335 | 336 | $flag = rmdir($_path); |
@@ -342,10 +343,10 @@ discard block |
||
| 342 | 343 | * @param $file |
| 343 | 344 | * @return bool |
| 344 | 345 | */ |
| 345 | - public function unlink($file) |
|
| 346 | - { |
|
| 346 | + public function unlink($file) |
|
| 347 | + {
|
|
| 347 | 348 | $flag = false; |
| 348 | - if ($this->checkFile($file)) { |
|
| 349 | + if ($this->checkFile($file)) {
|
|
| 349 | 350 | $flag = unlink(MODX_BASE_PATH . $this->relativePath($file)); |
| 350 | 351 | } |
| 351 | 352 | |
@@ -356,10 +357,10 @@ discard block |
||
| 356 | 357 | * @param $path |
| 357 | 358 | * @return bool |
| 358 | 359 | */ |
| 359 | - public function delete($path) |
|
| 360 | - { |
|
| 360 | + public function delete($path) |
|
| 361 | + {
|
|
| 361 | 362 | $path = MODX_BASE_PATH . $this->relativePath($path); |
| 362 | - switch (true) { |
|
| 363 | + switch (true) {
|
|
| 363 | 364 | case $this->checkDir($path): |
| 364 | 365 | $flag = $this->rmDir($path); |
| 365 | 366 | break; |
@@ -378,11 +379,11 @@ discard block |
||
| 378 | 379 | * @param bool $full |
| 379 | 380 | * @return string |
| 380 | 381 | */ |
| 381 | - public function getInexistantFilename($file, $full = false) |
|
| 382 | - { |
|
| 382 | + public function getInexistantFilename($file, $full = false) |
|
| 383 | + {
|
|
| 383 | 384 | $i = 1; |
| 384 | 385 | $file = $mainFile = MODX_BASE_PATH . $this->relativePath($file); |
| 385 | - while ($this->checkFile($file)) { |
|
| 386 | + while ($this->checkFile($file)) {
|
|
| 386 | 387 | $i++; |
| 387 | 388 | $out = $this->takeFileDir($file) . '/'; |
| 388 | 389 | $out .= $this->takeFileName($mainFile) . "({$i})." . $this->takeFileExt($file); |