|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Win\File; |
|
4
|
|
|
|
|
5
|
|
|
use Win\Calendar\DateTime; |
|
6
|
|
|
use const BASE_PATH; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Item dentro do Diretório |
|
10
|
|
|
* São outros diretório, arquivos, etc |
|
11
|
|
|
*/ |
|
12
|
|
|
abstract class DirectoryItem implements DirectoryItemInterface { |
|
13
|
|
|
|
|
14
|
|
|
const REGEXP_PATH = '@^(([a-z0-9._\-][\/]?))+$@'; |
|
15
|
|
|
const REGEXP_NAME = '@^(([a-z0-9._\-]?))+$@'; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
private $path; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Directory */ |
|
21
|
|
|
private $directory; |
|
22
|
|
|
|
|
23
|
|
|
/** @return string */ |
|
24
|
|
|
public function getPath() { |
|
25
|
|
|
return $this->path; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** @return string */ |
|
29
|
|
|
public function getAbsolutePath() { |
|
30
|
|
|
return BASE_PATH . DIRECTORY_SEPARATOR . $this->path; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Retorna o diretório pai |
|
35
|
|
|
* @return Directory |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getDirectory() { |
|
38
|
|
|
if (is_null($this->directory)) { |
|
39
|
|
|
$this->directory = new Directory(pathinfo($this->getPath(), PATHINFO_DIRNAME)); |
|
40
|
|
|
} |
|
41
|
|
|
return $this->directory; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** @return Date */ |
|
|
|
|
|
|
45
|
|
|
public function getLastModifiedDate(){ |
|
46
|
|
|
$ts = filemtime($this->getAbsolutePath()); |
|
47
|
|
|
return new \DateTime("@$ts"); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
/** @param string $path */ |
|
50
|
|
|
protected function setPath($path) { |
|
51
|
|
|
$this->path = $path; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function setDirectory(Directory $directory) { |
|
55
|
|
|
$this->directory = $directory; |
|
56
|
|
|
$path = $directory->getPath() . DIRECTORY_SEPARATOR . $this->__toString(); |
|
57
|
|
|
$this->setPath($path); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** @param string */ |
|
61
|
|
|
protected function setName($name) { |
|
62
|
|
|
$path = $this->getDirectory()->getPath() . DIRECTORY_SEPARATOR . $name; |
|
63
|
|
|
$this->setPath($path); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Renomeia |
|
68
|
|
|
* @param string $newName Novo nome |
|
69
|
|
|
* @return boolean |
|
70
|
|
|
*/ |
|
71
|
|
|
public function rename($newName) { |
|
72
|
|
|
$oldPath = $this->getAbsolutePath(); |
|
73
|
|
|
$this->setName($newName); |
|
74
|
|
|
return rename($oldPath, $this->getAbsolutePath()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Move para um novo diretório |
|
79
|
|
|
* @param Directory $newDirectory |
|
80
|
|
|
* @return boolean |
|
81
|
|
|
*/ |
|
82
|
|
|
public function move(Directory $newDirectory) { |
|
83
|
|
|
$oldPath = $this->getAbsolutePath(); |
|
84
|
|
|
$this->setDirectory($newDirectory); |
|
85
|
|
|
if (!$this->getDirectory()->exists()) { |
|
86
|
|
|
$this->getDirectory()->create(); |
|
87
|
|
|
} |
|
88
|
|
|
return rename($oldPath, $this->getAbsolutePath()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Define a permissão ao diretório |
|
93
|
|
|
* @param int $chmod |
|
94
|
|
|
* @return boolean |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setChmod($chmod = 0755) { |
|
97
|
|
|
return @chmod($this->getAbsolutePath(), $chmod); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** @return string */ |
|
101
|
|
|
public function getChmod() { |
|
102
|
|
|
clearstatcache(); |
|
103
|
|
|
return substr(decoct(fileperms($this->getAbsolutePath())), 2); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths