1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Win\Repositories\Filesystem; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Item dentro do Diretório |
7
|
|
|
* Podendo ser outro diretório, arquivos, etc |
8
|
|
|
*/ |
9
|
|
|
abstract class Storable |
10
|
|
|
{ |
11
|
|
|
const REGEXP_PATH = '@^(([a-zA-Z0-9._\-][\/]?))+$@'; |
12
|
|
|
const REGEXP_NAME = '@^(([a-zA-Z0-9._\-]?))+$@'; |
13
|
|
|
const DS = DIRECTORY_SEPARATOR; |
14
|
|
|
|
15
|
|
|
private string $path; |
16
|
|
|
private ?Directory $directory = null; |
17
|
|
|
|
18
|
|
|
/** @return string */ |
19
|
|
|
public function __toString() |
20
|
|
|
{ |
21
|
|
|
return $this->getPath(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** @return string */ |
25
|
|
|
public function getPath() |
26
|
|
|
{ |
27
|
|
|
return $this->path; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** @return string */ |
31
|
|
|
public function getAbsolutePath() |
32
|
|
|
{ |
33
|
|
|
return BASE_PATH . static::DS . $this->path; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Retorna o diretório pai |
38
|
|
|
* @return Directory |
39
|
|
|
*/ |
40
|
|
|
public function getDirectory() |
41
|
|
|
{ |
42
|
|
|
if (is_null($this->directory)) { |
43
|
|
|
$path = pathinfo($this->getPath(), PATHINFO_DIRNAME); |
44
|
|
|
$this->directory = new Directory($path); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->directory; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** @return string */ |
51
|
|
|
public function getName() |
52
|
|
|
{ |
53
|
|
|
return pathinfo($this->getAbsolutePath(), PATHINFO_FILENAME); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** @return string */ |
57
|
|
|
public function getBaseName() |
58
|
|
|
{ |
59
|
|
|
return pathinfo($this->getAbsolutePath(), PATHINFO_BASENAME); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** @return string */ |
63
|
|
|
public function getUpdatedAt() |
64
|
|
|
{ |
65
|
|
|
$ts = filemtime($this->getAbsolutePath()); |
66
|
|
|
|
67
|
|
|
return date('Y-m-d H:i:s', $ts); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** @param string $path */ |
71
|
|
|
protected function setPath($path) |
72
|
|
|
{ |
73
|
|
|
$this->path = $path; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|