32
32
* @property-read int|null $error Error code, one of `UPLOAD_ERR_*`.
33
33
* @property-read FormattedString|null $error_message A formatted message representing the error.
34
34
* @property-read string $pathname Pathname of the file.
35
- * @property-read string $extension The extension of the file. If any, the dot is included e.g.
36
- * ".zip".
37
35
* @property-read string $unsuffixed_name The name of the file without its extension.
38
- * @property-read bool $is_uploaded `true` if the file is uploaded, `false` otherwise.
39
- * @property-read bool $is_valid `true` if the file is valid, `false` otherwise.
40
- * See: {@see get_is_valid()}.
41
36
*/
42
37
class File implements ToArray, FileOptions
43
38
{
@@ -48,10 +43,7 @@ class File implements ToArray, FileOptions
48
43
* @uses get_size
49
44
* @uses get_error
50
45
* @uses get_error_message
51
- * @uses get_is_valid
52
46
* @uses get_pathname
53
- * @uses get_extension
54
- * @uses get_is_uploaded
55
47
*/
56
48
use AccessorTrait;
57
49
@@ -243,11 +235,12 @@ protected function get_error_message(): ?FormattedString
243
235
* A file is considered valid if it has no error code, if it has a size,
244
236
* if it has either a temporary name or a pathname and that the file actually exists.
245
237
*/
246
- protected function get_is_valid (): bool
247
- {
248
- return !$ this ->error
249
- && $ this ->size
250
- && ($ this ->tmp_name || ($ this ->pathname && file_exists ($ this ->pathname )));
238
+ public bool $ is_valid {
239
+ get {
240
+ return !$ this ->error
241
+ && $ this ->size
242
+ && ($ this ->tmp_name || ($ this ->pathname && file_exists ($ this ->pathname )));
243
+ }
251
244
}
252
245
253
246
private ?string $ pathname = null ;
@@ -334,32 +327,33 @@ public function to_array(): array
334
327
}
335
328
336
329
/**
337
- * Returns the extension of the file, if any.
330
+ * The extension of the file, if any.
338
331
*
339
332
* **Note**: The extension includes the dot e.g. ".zip". The extension is always in lower case.
340
333
*/
341
- protected function get_extension (): ?string
342
- {
343
- if (!$ this ->name ) {
344
- return null ;
345
- }
334
+ public ?string $ extension {
335
+ get {
336
+ if (!$ this ->name ) {
337
+ return null ;
338
+ }
346
339
347
- $ extension = pathinfo ($ this ->name , PATHINFO_EXTENSION );
340
+ $ extension = pathinfo ($ this ->name , PATHINFO_EXTENSION );
348
341
349
- if (!$ extension ) {
350
- return null ;
351
- }
342
+ if (!$ extension ) {
343
+ return null ;
344
+ }
352
345
353
- return '. ' . strtolower ($ extension );
346
+ return '. ' . strtolower ($ extension );
347
+ }
354
348
}
355
349
356
350
/**
357
- * Checks if a file is uploaded.
351
+ * Whether the file was uploaded.
358
352
*/
359
- protected function get_is_uploaded (): bool
360
- {
361
- return $ this ->tmp_name && is_uploaded_file ($ this ->tmp_name );
362
- }
353
+ public bool $ is_uploaded
354
+ {
355
+ get => $ this ->tmp_name && is_uploaded_file ($ this ->tmp_name );
356
+ }
363
357
364
358
/**
365
359
* Checks if the file matches a MIME class, a MIME type, or a file extension.
0 commit comments