Hi guys, I’m in the process of writing a fairly sizable application that will have to manage quite a bit of file data. As is good practice I don’t want to store the files as BLOBs in the database as that makes an already large database almost impossible to maintain (e.g. backup regularly, etc) and want to store the files (e.g. images, documents, etc) in the file system. Because of the large number of files (i.e. tens of thousands) it’s also necessary to split files within each folder (e.g. images) into multiple folders using some sort of a partitioning strategy which may be completely independent of the record with which the file is associated or the file name or may be derived based on either the record or the file name (e.g. 001, 002, 003… OR A, B, C…, etc). The strategy would need to depend on the number of files expected and the sparsity of the data.
I have searched both Yii web resources and the internet for an implementation of something like this or something similar in another language but havn’t found anything useful, which is rather surprising given that I would have thought many people would need something like this. Perhaps people just took the simple hack route rather than writing a class (or multiple classes) to do this. So, I’m currently looking to implement it myself and most likely share is as an extension or at least an example.
I’m thinking of implementing it more or less similar to CAssetManager but it will probably be a bit more complex. It would be called something like EContentManager, or EFileManager or EFileSystemManager to stay consistent with the naming of CAssetManager or perhaps even just EFileSystem. I will also probably create something something like IDirectoryPartitioningStrategy and concrete implementations of one or more partitioning strategies (GoF strategy pattern), or perhaps rather than creating too many files maybe even do this in the FileSystem implementation itself (although that’s technically not the best way to do it). I’m thinking I might implement an abstract class which deals with the basics and then perhaps a concrete class which is specific to my particular application and has knowledge of the specifics types of files I will be storing in the file system (e.g. Images, Documents, Logos). I may also implement file name creation using a strategy pattern.
To give you an idea of what I was thinking in terms of implementation, the class will have properties such as baseUrl and basePath like CAssetManager but then on top of that will have other properties like imageDirBasePath, logoDirBasePath, documentDirBasePath and largeImageDirBasePath, mediumImageDirBasePath, smallImageDirPath, which will be application specific. There will also be methods like ensureStructure, which will ensure the file system structure is always right and will be called from the init method. Then there would also be methods like createLargeImagePath($fileName), createDocumentPath($fileName), etc that will use the partitioning strategy to create a path to which the file should be saved.
I’m interested to know if anyone has done something similar in the past or would have any suggestions. I’m particularly interested to hear from anyone on the Yii core team (e.g. Qiang, Sam Dark, Y!!) or any other experienced developers with plenty of Yii or general OO experience. Hope what I’m trying to achieve makes sense.