-
Notifications
You must be signed in to change notification settings - Fork 9
Architecture
The basic structure of Filebanksta is very simple. It has a virtual filesystem consisting of folders and files. One root folder can have n+1 subfolders, and all folders can contain 0-n files.
Every file belongs to a profile. Profiles offer the possibility to differentiate the roles and functions of files uploaded to the system.
For example profile "default" could just store a file as-is, and profile "versioned" could create context-specific versions for a file: thumbnails for images, HTML 5 videos from videos, pdf:s from open office documents, etc.
Filebanksta is extended via plugins. A plugin connects to 1-n profiles and provides for certain types of files (image versioning plugin only reacts for images).
Plugins listen for events. Filebanksta implements the observer pattern (with the Symfony 2 event dispatcher). Plugins just register with a set of events and are notified when something interesting happens (a file is uploaded, deleted, etc).
Filebanksta separates the concerns of a file library application to easily digestible subsystems, each implementing a common interface.
Files and folders are always just "dum" value items. Filebanksta defines an interface for both and supplies a default implementation.
<?php
$folder = FolderItem::create(array(
'id' => 3,
'parent_id' => 2,
'name' => 'subfolder',
'url' => 'folder/subfolder',
));
$file = FileItem::create(array(
'id' => 1,
'folder_id' => 3,
'mimetype' => 'image/png',
'profile' => 'versioned',
'size' => 5000,
'name' => 'doctor-vesala.png',
'link' => 'folder/subfolder/doctor-vesala.png',
'date_uploaded' => new DateTime('2012-01-01')
));
?>
Backend is responsible for storing (and retrieving, and deleting, of course) the metadata of the filebanksta. The virtual folders and files reside here.
At the moment filebanksta supplies implementations for SQL databases via both Zend DB and Doctrine 2, and MongoDB via PECL's Mongo extension.
Of course the backend could be something radically different: XML inside a physical directory structure inside a filesystem or whatnot. Just implement the interface and you're good to go.
<?php
use Xi\Filelib\FileLibrary;
use Xi\Filelib\Backend\Doctrine2Backend;
$filelib = new FileLibrary();
$backend = new Doctrine2Backend();
$backend->setEntityManager($entityManager);
$filelib->setBackend($backend);
?>
Storage is responsible for storing the physical files. Filebanksta supplies filesystem, GridFS and Amazon S3 implementations, and a composite storage you can utilize to store your files within multiple storage instances.
<?php
use Xi\Filelib\Storage\FilesystemStorage;
$storage = new FilesystemStorage();
$storage->setRoot('/some/root');
$storage->setDirectoryPermission("700");
$storage->setFilePermission("600");
$filelib->setStorage($storage);