1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Filesystem\File; |
4
|
|
|
|
5
|
|
|
trait HasInformation |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Check whether the entree is a directory. |
10
|
|
|
* |
11
|
|
|
* @return bool |
12
|
|
|
*/ |
13
|
|
|
public function isDir() |
14
|
|
|
{ |
15
|
|
|
return $this->getType() === 'dir'; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Check whether the entree is a file. |
20
|
|
|
* |
21
|
|
|
* @return bool |
22
|
|
|
*/ |
23
|
|
|
public function isFile() |
24
|
|
|
{ |
25
|
|
|
return $this->getType() === 'file'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Retrieve the entree type (file|dir). |
30
|
|
|
* |
31
|
|
|
* @return string file or dir |
32
|
|
|
*/ |
33
|
|
|
public function getType() |
34
|
|
|
{ |
35
|
|
|
$metadata = $this->filesystem->getMetadata($this->path); |
36
|
|
|
|
37
|
|
|
return $metadata ? $metadata['type'] : 'dir'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the file's timestamp. |
42
|
|
|
* |
43
|
|
|
* @return string|false The timestamp or false on failure. |
44
|
|
|
*/ |
45
|
|
|
public function getTimestamp() |
46
|
|
|
{ |
47
|
|
|
return $this->filesystem->getTimestamp($this->path); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the file's mimetype. |
52
|
|
|
* |
53
|
|
|
* @return string|false The file mime-type or false on failure. |
54
|
|
|
*/ |
55
|
|
|
public function getMimetype() |
56
|
|
|
{ |
57
|
|
|
return $this->filesystem->getMimetype($this->path); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get the file's visibility. |
62
|
|
|
* |
63
|
|
|
* @return string|false The visibility (public|private) or false on failure. |
64
|
|
|
*/ |
65
|
|
|
public function getVisibility() |
66
|
|
|
{ |
67
|
|
|
return $this->filesystem->getVisibility($this->path); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the file's metadata. |
72
|
|
|
* |
73
|
|
|
* @return array|false The file metadata or false on failure. |
74
|
|
|
*/ |
75
|
|
|
public function getMetadata() |
76
|
|
|
{ |
77
|
|
|
return $this->filesystem->getMetadata($this->path); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get the file size. |
82
|
|
|
* |
83
|
|
|
* @return int|false The file size or false on failure. |
84
|
|
|
*/ |
85
|
|
|
public function getSize() |
86
|
|
|
{ |
87
|
|
|
return $this->filesystem->getSize($this->path); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|