Completed
Push — master ( 707e60...bec0f5 )
by Jean-Christophe
01:22
created

FsUtils::safeMkdir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace micro\utils;
4
5
/**
6
 * @author jc
7
 * @version 1.0.0.1
8
 */
9
class FsUtils {
10
11
	public static function glob_recursive($pattern, $flags=0) {
12
		$files=glob($pattern, $flags);
13
		foreach ( glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir ) {
14
			$files=array_merge($files, self::glob_recursive($dir . '/' . basename($pattern), $flags));
15
		}
16
		return $files;
17
	}
18
19
	public static function deleteAllFilesFromFolder($folder) {
20
		$files=glob($folder . '/*');
21
		foreach ( $files as $file ) {
22
			if (is_file($file))
23
				unlink($file);
24
		}
25
	}
26
27
	public static function safeMkdir($dir){
28
		if(!is_dir($dir))
29
			return mkdir($dir,0777,true);
30
		return true;
31
	}
32
33
	public static function cleanPathname($path){
34
		if(StrUtils::isNotNull($path)){
35
			if(DS==="/")
36
				$path=\str_replace("\\", DS, $path);
37
			else
38
				$path=\str_replace("/", DS, $path);
39
			$path=\str_replace(DS.DS, DS, $path);
40
			if(!StrUtils::endswith($path, DS)){
41
				$path=$path.DS;
42
			}
43
		}
44
		return $path;
45
	}
46
}