-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/fileitem factory #362
base: 2.1
Are you sure you want to change the base?
Conversation
# Conflicts: # tests/Token/TokenTest.php # tests/Util/FileUploadNormalizerTest.php
# Conflicts: # tests/EventListener/AdminEmailTokenListenerTest.php
# Conflicts: # tests/Gateway/MailerGatewayTest.php
Is that what you need @aschempp? If so, I'll merge this :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good except for my notes :)
} | ||
|
||
/** | ||
* @throws InvalidFileItemException if the information cannot be fetched automatically (e.g. missing mime type guesser service) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @throws InvalidFileItemException if the information cannot be fetched automatically (e.g. missing mime type guesser service) | |
* @throws InvalidFileItemException if the file does not exist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both comments are correct, you would need to merge them in your suggestion.
{ | ||
$stream = $virtualFilesystem->readStream($file->getPath()); | ||
|
||
return FileItem::fromStream($stream, $file->getName(), $file->getMimeType(), $file->getFileSize()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does $file->getName()
return the "base name" only, or should we apply basename()
as well here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does whatever the implementation of the virtualfilesystem does. We don't care here.
public function createFromLocalPath(string $path): FileItem | ||
{ | ||
if (!(new Filesystem())->exists($path)) { | ||
throw new InvalidFileItemException(\sprintf('The file "%s" does not exist.', $path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could use the Symfony Filesystem FileNotFoundException
here instead? The we also wouldn't need to add a new exception to NC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's best practice to use domain exceptions.
Replaces #360.