murph-doc/docs/utils/file_attribute.md

23 lines
703 B
Markdown
Raw Normal View History

2022-05-07 13:47:17 +02:00
# File attribute
`App\Core\File\FileAttribute::handleFile` transforms a file path to an instance of `Symfony\Component\HttpFoundation\File\File`. You can specify another class if needed.
If the path is `null` or if the file does not exist, it returns `null`.
2023-02-09 21:50:06 +01:00
```php-inline
2022-05-07 13:47:17 +02:00
use App\Core\File\FileAttribute;
use App\Foo\Bar;
$path = 'path/to/file';
$file = FileAttribute::handleFile($path); // returns an instance of File
2022-05-07 13:48:51 +02:00
$path = 'path/to/file';
$file = FileAttribute::handleFile($path, Bar::class); // returns an instance of Bar
2022-05-07 13:47:17 +02:00
$path = 'path/to/removed_file';
$file = FileAttribute::handleFile($path); // returns null
$path = null;
$file = FileAttribute::handleFile($path); // returns null
```