1 | <?php |
||
24 | final class File implements FileInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $name; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $path; |
||
35 | |||
36 | /** |
||
37 | * @var string; |
||
38 | */ |
||
39 | private $rootPath; |
||
40 | |||
41 | /** |
||
42 | * @var string; |
||
43 | */ |
||
44 | private $relativePath; |
||
45 | |||
46 | /** |
||
47 | * @var integer |
||
48 | */ |
||
49 | private $size; |
||
50 | |||
51 | /** |
||
52 | * @var \DateTimeInterface |
||
53 | */ |
||
54 | private $createdAt; |
||
55 | |||
56 | /** |
||
57 | * @var \DateTimeInterface |
||
58 | */ |
||
59 | private $modifiedAt; |
||
60 | |||
61 | public function __construct($name, $path, $rootPath, $size, $createdAt, $modifiedAt) |
||
62 | { |
||
63 | $this->name = $name; |
||
64 | $this->path = $path; |
||
65 | $this->rootPath = rtrim(is_null($rootPath) ? '' : $rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
||
66 | $this->size = $size; |
||
67 | $this->createdAt = (is_numeric($createdAt)) ? date_timestamp_set(new \DateTime(), $createdAt) : clone $createdAt; |
||
68 | $this->modifiedAt = (is_numeric($modifiedAt)) ? date_timestamp_set(new \DateTime(), $modifiedAt) : clone $modifiedAt; |
||
69 | $this->relativePath = null; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function getName() |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | public function getPath() |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | public function getRootPath() |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function getRelativePath() |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function getSize() |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function getCreatedAt() |
||
130 | |||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | public function getModifiedAt() |
||
138 | |||
139 | /** |
||
140 | * Create File instance from local, mounted filesystem. |
||
141 | * |
||
142 | * @param string $path Path to file. |
||
143 | * @param null|string $rootPath Root path of file. |
||
144 | * @param null|string $name Filename to use instead of original one (if provided). |
||
145 | * @return File Created backup file instance. |
||
146 | */ |
||
147 | public static function fromLocal($path, $rootPath = null, $name = null) |
||
158 | |||
159 | /** |
||
160 | * Create file instane from \SplFileInfo instance. |
||
161 | * |
||
162 | * @param \SplFileInfo $file |
||
163 | * @param null|string $rootPath Root path of file. |
||
164 | * @param null|string $name Filename to use instead of original one (if provided). |
||
165 | * @return static |
||
166 | */ |
||
167 | public static function fromSplFileInfo(\SplFileInfo $file, $rootPath = null, $name = null) |
||
178 | } |