1 | <?php |
||
25 | class File |
||
26 | { |
||
27 | /** |
||
28 | * File extension separator |
||
29 | * @const string |
||
30 | */ |
||
31 | const EXTENSION_SEPARATOR = '.'; |
||
32 | |||
33 | /** |
||
34 | * File's name including the path |
||
35 | * @var null|string |
||
36 | */ |
||
37 | private $filename = null; |
||
38 | |||
39 | /** |
||
40 | * File's extension - For no extension a blank string will be used |
||
41 | * @var null|string |
||
42 | */ |
||
43 | private $extension = null; |
||
44 | |||
45 | /** |
||
46 | * File's name without extension |
||
47 | * @var null|string |
||
48 | */ |
||
49 | private $name = null; |
||
50 | |||
51 | /** |
||
52 | * Whether the file has an extension or if it is set by us |
||
53 | * @var bool |
||
54 | */ |
||
55 | private $hasExtension = false; |
||
56 | |||
57 | /** |
||
58 | * @var null|ContentFactory |
||
59 | */ |
||
60 | private $contentFactory = null; |
||
61 | |||
62 | /** |
||
63 | * File constructor. |
||
64 | * |
||
65 | * @param string $filename |
||
66 | */ |
||
67 | 39 | public function __construct(string $filename) |
|
82 | |||
83 | /** |
||
84 | * States whether the file actually exists on disk |
||
85 | * @return bool |
||
86 | */ |
||
87 | 19 | public function exists(): bool |
|
91 | |||
92 | /** |
||
93 | * States whether the file is readable |
||
94 | * @return bool |
||
95 | */ |
||
96 | 6 | public function isReadable(): bool |
|
100 | |||
101 | /** |
||
102 | * @return bool |
||
103 | */ |
||
104 | 7 | public function isWritable(): bool |
|
113 | |||
114 | /** |
||
115 | * Write content to the current file |
||
116 | * |
||
117 | * @param \NeedleProject\FileIo\Content\ContentInterface $content |
||
118 | * @return \NeedleProject\FileIo\File |
||
119 | * @throws \NeedleProject\FileIo\Exception\PermissionDeniedException |
||
120 | */ |
||
121 | 3 | public function write(ContentInterface $content): File |
|
129 | |||
130 | /** |
||
131 | * @return \NeedleProject\FileIo\Content\ContentInterface |
||
132 | * @throws \NeedleProject\FileIo\Exception\FileNotFoundException |
||
133 | * @throws \NeedleProject\FileIo\Exception\IOException |
||
134 | * @throws \NeedleProject\FileIo\Exception\PermissionDeniedException |
||
135 | */ |
||
136 | 6 | public function getContent(): ContentInterface |
|
157 | |||
158 | /** |
||
159 | * Deletes the current file |
||
160 | * @return bool |
||
161 | * @throws \NeedleProject\FileIo\Exception\IOException |
||
162 | */ |
||
163 | 3 | public function delete(): bool |
|
173 | |||
174 | /** |
||
175 | * State existence of a file's extension |
||
176 | * @return bool |
||
177 | */ |
||
178 | 10 | public function hasExtension(): bool |
|
182 | |||
183 | /** |
||
184 | * Get file's extension |
||
185 | * @return string |
||
186 | */ |
||
187 | 4 | public function getExtension(): string |
|
191 | |||
192 | /** |
||
193 | * Get file's name without extension |
||
194 | * @return string |
||
195 | */ |
||
196 | 4 | public function getName(): string |
|
200 | |||
201 | /** |
||
202 | * Get file's name with extension |
||
203 | * @return string |
||
204 | */ |
||
205 | 5 | public function getBasename(): string |
|
212 | |||
213 | /** |
||
214 | * Returns a factory responsible for creating appropriate content |
||
215 | * @return \NeedleProject\FileIo\Factory\ContentFactory |
||
216 | */ |
||
217 | 1 | protected function getFactory(): ContentFactory |
|
224 | } |
||
225 |