1 | <?php |
||
21 | class File extends FileAggregateRoot |
||
22 | { |
||
23 | /** |
||
24 | * The id. |
||
25 | * |
||
26 | * @var FileId |
||
27 | */ |
||
28 | protected $id; |
||
29 | |||
30 | /** |
||
31 | * Created on. |
||
32 | * |
||
33 | * @var \DateTimeImmutable |
||
34 | */ |
||
35 | protected $createdOn; |
||
36 | |||
37 | /** |
||
38 | * The file mime type. |
||
39 | * |
||
40 | * @var FileMimeType |
||
41 | */ |
||
42 | protected $mimeType; |
||
43 | |||
44 | /** |
||
45 | * The file name. |
||
46 | * |
||
47 | * @var FileName |
||
48 | */ |
||
49 | protected $name; |
||
50 | |||
51 | /** |
||
52 | * Updated on. |
||
53 | * |
||
54 | * @var \DateTimeImmutable |
||
55 | */ |
||
56 | protected $updatedOn; |
||
57 | |||
58 | /** |
||
59 | * Constructor. |
||
60 | * |
||
61 | * @param FileId $anId The id |
||
62 | * @param FileName $aName The file name |
||
63 | * @param FileMimeType $aMimeType The file mime type |
||
64 | */ |
||
65 | public function __construct(FileId $anId, FileName $aName, FileMimeType $aMimeType) |
||
75 | |||
76 | /** |
||
77 | * Gets the id. |
||
78 | * |
||
79 | * @return FileId |
||
80 | */ |
||
81 | public function id() |
||
85 | |||
86 | /** |
||
87 | * Gets the created on. |
||
88 | * |
||
89 | * @return \DateTimeImmutable |
||
90 | */ |
||
91 | public function createdOn() |
||
95 | |||
96 | /** |
||
97 | * Gets the file mime type. |
||
98 | * |
||
99 | * @return FileMimeType |
||
100 | */ |
||
101 | public function mimeType() |
||
105 | |||
106 | /** |
||
107 | * Gets the file name. |
||
108 | * |
||
109 | * @return FileName |
||
110 | */ |
||
111 | public function name() |
||
115 | |||
116 | /** |
||
117 | * Overwrites the file. |
||
118 | * |
||
119 | * @param FileName $aName The file name |
||
120 | * @param FileMimeType $aMimeType The file mime type |
||
121 | */ |
||
122 | public function overwrite(FileName $aName, FileMimeType $aMimeType) |
||
130 | |||
131 | /** |
||
132 | * Removes the file. |
||
133 | */ |
||
134 | public function remove() |
||
138 | |||
139 | /** |
||
140 | * Renames the file. |
||
141 | * |
||
142 | * @param FileName $aName The file name |
||
143 | * |
||
144 | * @throws FileNameException when the file name extension is different of the current |
||
145 | */ |
||
146 | public function rename(FileName $aName) |
||
157 | |||
158 | /** |
||
159 | * Gets the updated on. |
||
160 | * |
||
161 | * @return \DateTimeImmutable |
||
162 | */ |
||
163 | public function updatedOn() |
||
167 | |||
168 | /** |
||
169 | * Magic method that represents the file domain object in string format. |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | public function __toString() |
||
177 | |||
178 | /** |
||
179 | * Gets the available mime types in scalar type. |
||
180 | * |
||
181 | * This method is an extension point that it allows |
||
182 | * to add more mime types easily in the domain. |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | protected function availableMimeTypes() |
||
190 | |||
191 | /** |
||
192 | * Sets the given mime type in the file scope. |
||
193 | * |
||
194 | * @param FileMimeType $aMimeType The mime type |
||
195 | * |
||
196 | * @throws FileMimeTypeException when the given mime type is not support for the file |
||
197 | */ |
||
198 | private function setMimeType(FileMimeType $aMimeType) |
||
205 | } |
||
206 |