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

[Doctrine] StoreAsFilename #97

Open
kbond opened this issue Mar 3, 2023 · 0 comments
Open

[Doctrine] StoreAsFilename #97

kbond opened this issue Mar 3, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@kbond
Copy link
Member

kbond commented Mar 3, 2023

If using StoreAsPath and all your filename prefixes are the same (ie some/dir/filename.ext) it can be a waste of resources to store the same prefix in the db over and over.

I propose a StoreAsFilename mapping:

#[StoreAsFilename(
    filesystem: 'public'
    fileNamer: new Expression('{this.title|slug}-{name}{ext}'), // would throw an exception if contains /'s
    directoryNamer: new Expression('some/dir'),
)]
private File $file;

When saving to db, just the filename would be stored. When loading, the directoryNamer would be used to create the prefix and append the filename to it.

As a slight perf boost, we could add a String Namer that doesn't require processing and just returns the string. Probably a SelfGeneratingNamer concept should be added.

#[StoreAsFilename(
    filesystem: 'public'
    fileNamer: new Expression('{this.title|slug}-{name}{ext}'),
    directoryNamer: new String('some/dir'),
)]
private File $file;
@kbond kbond added the enhancement New feature or request label Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant