[TYPO3-media] Where to put method: getUniqueName and sanitizeFileName

Ingmar Schlecht ingmar at typo3.org
Mon Nov 28 08:42:08 CET 2011


Hi Fabien,

Am 28.11.11 06:18, schrieb Fabien Udriot:
> Hi,
>
> I need your opinion about API organization. The current situation is the
> following:
>
> * method getUniqueName() is in the Storage. Purpose: make sure the file
> name is unique.
> * method sanitizeFileName() in in the Local Driver. Purpose: make the
> file name be web-friendly (remove white spaces,...)
>
> Both methods have something in common since they are dealing with the
> file name and I wonder whether they are at right place. Why aren't they
> at the same spot?
>
> At the first glance, getUniqueName() would be rather something for the
> driver, isn't? E.g An Amazon storage might have different way of getting
> an unique name instead of adding a "_01" suffix at the end of the file.

Yes, I think so too. Some Drivers may not even require file names to be 
unique (as the identifier could be based on something else than the file 
path and name, and then it doesn't really matter what the file name is). 
So maybe the method should be called getAllowedNameInFolder($inputName, 
t3lib_file_Folder $targetFolder) and then the Driver applies the 
uniqueness-check if necessary, and also does other cleanup that might be 
needed for filenames on that particular Driver.

So I would merge the functionality of both the sanitize and the 
uniqueness function and put them to that new function 
getAllowedNameInFolder which would be located in the Driver. There 
should be a default implementation of that function in the Abstract 
driver which just applies the same logic we had before: Sanitze the 
filename first (e.g. replace spaces by underscores), and then check 
uniqueness. If drivers have special requirements, they can just override 
the method ofthe abstract driver by their own implementation.

What do you think?

cheers
Ingmar

> So, what to do? I need an answer since I have a bug in the upload
> procedure and will need to update the API: the File Name is currently
> not sanitized. (e.g "My File.jpg" is not renamed "My_File.jpg")
>
> * Keep the situation as it is?
> * Move method around? What do you suggest here? Take also into
> consideration that we might possibly share these functions among drivers
> that are just a remote regular file system (FTP, WebDav, whatever, ...).
> I am thinking towards some Static Utility method. Just a thought!
>
> I am on-line in case it would need further explanation.
>
> Have a nice day.
>
> Fabien
> _______________________________________________
> TYPO3-project-media mailing list
> TYPO3-project-media at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-media



More information about the TYPO3-project-media mailing list