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 | * File constructor. |
||
59 | * |
||
60 | * @param string $filename |
||
61 | */ |
||
62 | 39 | public function __construct(string $filename) |
|
77 | |||
78 | /** |
||
79 | * States whether the file actually exists on disk |
||
80 | * @return bool |
||
81 | */ |
||
82 | 19 | public function exists(): bool |
|
86 | |||
87 | /** |
||
88 | * States whether the file is readable |
||
89 | * @return bool |
||
90 | */ |
||
91 | 6 | public function isReadable(): bool |
|
95 | |||
96 | /** |
||
97 | * @return bool |
||
98 | */ |
||
99 | 7 | public function isWritable(): bool |
|
108 | |||
109 | /** |
||
110 | * Write content to the current file |
||
111 | * |
||
112 | * @param \NeedleProject\FileIo\Content\ContentInterface $content |
||
113 | * @return \NeedleProject\FileIo\File |
||
114 | * @throws \NeedleProject\FileIo\Exception\PermissionDeniedException |
||
115 | */ |
||
116 | 3 | public function write(ContentInterface $content): File |
|
124 | |||
125 | /** |
||
126 | * @return \NeedleProject\FileIo\Content\ContentInterface |
||
127 | * @throws \NeedleProject\FileIo\Exception\FileNotFoundException |
||
128 | * @throws \NeedleProject\FileIo\Exception\IOException |
||
129 | * @throws \NeedleProject\FileIo\Exception\PermissionDeniedException |
||
130 | */ |
||
131 | 6 | public function getContent(): ContentInterface |
|
151 | |||
152 | /** |
||
153 | * Deletes the current file |
||
154 | * @return bool |
||
155 | * @throws \NeedleProject\FileIo\Exception\IOException |
||
156 | */ |
||
157 | 3 | public function delete(): bool |
|
167 | |||
168 | /** |
||
169 | * State existence of a file's extension |
||
170 | * @return bool |
||
171 | */ |
||
172 | 10 | public function hasExtension(): bool |
|
176 | |||
177 | /** |
||
178 | * Get file's extension |
||
179 | * @return string |
||
180 | */ |
||
181 | 4 | public function getExtension(): string |
|
185 | |||
186 | /** |
||
187 | * Get file's name without extension |
||
188 | * @return string |
||
189 | */ |
||
190 | 4 | public function getName(): string |
|
194 | |||
195 | /** |
||
196 | * Get file's name with extension |
||
197 | * @return string |
||
198 | */ |
||
199 | 5 | public function getBasename(): string |
|
206 | } |
||
207 |