| 1 | FileRepo Architecture {#filerepoarch} |
| 2 | ===================== |
| 3 | |
| 4 | Some quick notes on the file/repository architecture. |
| 5 | |
| 6 | Functionality is, as always, driven by data model. |
| 7 | |
| 8 | * The repository object stores configuration information about a file storage |
| 9 | method. |
| 10 | |
| 11 | * The file object is a process-local cache of information about a particular |
| 12 | file. |
| 13 | |
| 14 | Thus the file object is the primary public entry point for obtaining information |
| 15 | about files, since access via the file object can be cached, whereas access via |
| 16 | the repository should not be cached. |
| 17 | |
| 18 | Functions which can act on any file specified in their parameters typically find |
| 19 | their place either in the repository object, where reference to |
| 20 | repository-specific configuration is needed, or in static members of File or |
| 21 | FileRepo, where no such configuration is needed. |
| 22 | |
| 23 | File objects are generated by a factory function from the repository. The |
| 24 | repository thus has full control over the behavior of its subsidiary file |
| 25 | class, since it can subclass the file class and override functionality at its |
| 26 | whim. Thus there is no need for the File subclass to query its parent repository |
| 27 | for information about repository-class-dependent behavior -- the file subclass |
| 28 | is generally fully aware of the static preferences of its repository. Limited |
| 29 | exceptions can be made to this rule to permit sharing of functions, or perhaps |
| 30 | even entire classes, between repositories. |
| 31 | |
| 32 | These rules alone still do lead to some ambiguity -- it may not be clear whether |
| 33 | to implement some functionality in a repository function with a filename |
| 34 | parameter, or in the file object itself. |
| 35 | |
| 36 | So we introduce the following rule: the file subclass is smarter than the |
| 37 | repository subclass. The repository should in general provide a minimal API |
| 38 | needed to access the storage backend efficiently. |
| 39 | |
| 40 | In particular, note that I have not implemented any database access in |
| 41 | LocalRepo.php. LocalRepo provides only file access, and LocalFile provides |
| 42 | database access and higher-level functions such as cache management. |
| 43 | |
| 44 | Tim Starling, June 2007 |