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