Skip to content
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

Open
wants to merge 13 commits into
base: 2.1
Choose a base branch
from
Open

Feature/fileitem factory #362

wants to merge 13 commits into from

Conversation

Toflar
Copy link
Member

@Toflar Toflar commented Sep 17, 2024

Replaces #360.

@Toflar Toflar added this to the 2.1 milestone Sep 17, 2024
config/services.php Outdated Show resolved Hide resolved
@Toflar Toflar marked this pull request as ready for review September 19, 2024 12:08
@Toflar
Copy link
Member Author

Toflar commented Sep 19, 2024

Is that what you need @aschempp? If so, I'll merge this :)

Copy link
Member

@aschempp aschempp left a 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @throws InvalidFileItemException if the information cannot be fetched automatically (e.g. missing mime type guesser service)
* @throws InvalidFileItemException if the file does not exist)

Copy link
Member Author

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());
Copy link
Member

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?

Copy link
Member Author

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));
Copy link
Member

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants