1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Migratio\Resource\Request; |
4
|
|
|
|
5
|
|
|
class BaseRequestProcess |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var $paths |
|
|
|
|
9
|
|
|
*/ |
10
|
|
|
public static $paths; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @param $path |
14
|
|
|
*/ |
15
|
|
|
public static function chmod($path) |
16
|
|
|
{ |
17
|
|
|
$dir = new \DirectoryIterator($path); |
18
|
|
|
|
19
|
|
|
foreach ($dir as $item) { |
20
|
|
|
|
21
|
|
|
chmod($item->getPathname(), 0777); |
22
|
|
|
|
23
|
|
|
if ($item->isDir() && !$item->isDot()) { |
24
|
|
|
self::chmod($item->getPathname()); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public static function getAllDirectories() |
33
|
|
|
{ |
34
|
|
|
$list = []; |
35
|
|
|
|
36
|
|
|
$paths = self::$paths; |
37
|
|
|
|
38
|
|
|
foreach ($paths as $path){ |
39
|
|
|
$globPaths = array_filter(glob($path.'/*'), 'is_dir'); |
|
|
|
|
40
|
|
|
foreach ($globPaths as $reelPath){ |
41
|
|
|
$list[]=$reelPath; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $list; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
public static function getAllFiles() |
52
|
|
|
{ |
53
|
|
|
$directories = self::getAllDirectories(); |
54
|
|
|
|
55
|
|
|
$list = []; |
56
|
|
|
|
57
|
|
|
foreach ($directories as $directory){ |
58
|
|
|
|
59
|
|
|
foreach (glob($directory."/*.php") as $file) { |
60
|
|
|
|
61
|
|
|
$list[self::getFileName($directory)][]=$file; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $list; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param $path |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public static function getFileName($path) |
73
|
|
|
{ |
74
|
|
|
$pathParse = explode ("/",$path); |
75
|
|
|
|
76
|
|
|
return end($pathParse); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param $tables |
81
|
|
|
*/ |
82
|
|
|
public static function setDirectoryForTableNames($tables) |
83
|
|
|
{ |
84
|
|
|
$directories = self::getAllDirectories(); |
85
|
|
|
|
86
|
|
|
$mainPath = self::$paths[0].''; |
87
|
|
|
|
88
|
|
|
$mkdirResults = []; |
89
|
|
|
|
90
|
|
|
foreach ($tables as $table){ |
91
|
|
|
if(!isset($directories[$table])){ |
92
|
|
|
|
93
|
|
|
//get path and set mkdir |
94
|
|
|
$path = $mainPath.'/'.ucfirst($table); |
95
|
|
|
if(!file_exists($path)){ |
96
|
|
|
$mkdirResults[] = mkdir($path, 0777); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
dd(self::getAllDirectories(),$tables,$mkdirResults); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|