Skip to content

[Doctrine] StoreAsFilename #97

Open
@kbond

Description

@kbond

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions