1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Win\File; |
4
|
|
|
|
5
|
|
|
use Win\Request\Server; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Diretorio de arquivos |
9
|
|
|
*/ |
10
|
|
|
class Directory { |
11
|
|
|
|
12
|
|
|
private $path; |
13
|
|
|
|
14
|
|
|
public function __construct($path) { |
15
|
|
|
$this->path = str_replace(['///', '//'], ['/', '/'], $path . '/'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function __toString() { |
19
|
|
|
return $this->path; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getPath() { |
23
|
|
|
return $this->path; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function setPath($path) { |
27
|
|
|
$this->path = $path; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Retorna TRUE se é um diretorio |
32
|
|
|
* @return boolean |
33
|
|
|
*/ |
34
|
|
|
public function exists(){ |
35
|
|
|
return is_dir($this->path); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Cria o diretorio para salvar a imagem |
40
|
|
|
* @param string $pathetorio Caminho do novo diretorio |
|
|
|
|
41
|
|
|
* @param int $chmod permissões deste diretório |
42
|
|
|
* @return boolean Retora TRUE caso obtenha algum sucesso |
43
|
|
|
*/ |
44
|
|
|
public function create($chmod = 0755) { |
45
|
|
|
if (Server::isLocalHost()) { |
46
|
|
|
umask(0); |
47
|
|
|
$chmod = 0777; |
48
|
|
|
} |
49
|
|
|
if (!file_exists($this->path)) { |
50
|
|
|
$success = @mkdir($this->path, $chmod, STREAM_MKDIR_RECURSIVE); |
51
|
|
|
return $success; |
52
|
|
|
} |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Renomeia o diretorio |
58
|
|
|
* @param string $newName Caminho para o novo diretorio |
59
|
|
|
* @return boolean |
60
|
|
|
*/ |
61
|
|
|
public function rename($newName) { |
62
|
|
|
if ($this->path != $newName) { |
63
|
|
|
rename($this->path, $newName); |
64
|
|
|
return true; |
65
|
|
|
} |
66
|
|
|
return false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Exclui o diretorio, e os arquivos dentro dele |
71
|
|
|
* @param string $path |
|
|
|
|
72
|
|
|
* @return boolean |
73
|
|
|
*/ |
74
|
|
|
public function remove() { |
75
|
|
|
$path = str_replace('//', '/', $this->path); |
76
|
|
|
if (is_dir($path)): |
77
|
|
|
$this->removeAllFiles(); |
78
|
|
|
return rmdir($path); |
79
|
|
|
else: |
80
|
|
|
return false; |
81
|
|
|
endif; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** Exclui os arquivos deste diretorio */ |
85
|
|
|
protected function removeAllFiles() { |
86
|
|
|
$path = str_replace('//', '/', $this->path); |
87
|
|
|
$files = array_diff(scandir($path), ['.', '..']); |
88
|
|
|
foreach ($files as $file) { |
89
|
|
|
if (is_dir("$path/$file")) { |
90
|
|
|
$subDirectory = new Directory("$path/$file"); |
91
|
|
|
$subDirectory->remove(); |
92
|
|
|
} else { |
93
|
|
|
unlink("$path/$file"); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.