xi/filelib
xi/filelib is a file management library for Laravel that streamlines uploads, storage, and manipulation. It offers a clean, consistent API for working with files across disks, plus helpers for validation, naming, and retrieval, cutting boilerplate so you can manage assets quickly.
Install the library and its optional companions (image handling lives in a separate package in the xi ecosystem):
composer require xi/filelib
# if you need thumbnails/versions:
composer require xi/filelib-image
The package targets PHP 5.5. On a modern runtime expect to need --ignore-platform-reqs plus some compatibility shimming before it boots cleanly.
Before writing any code, understand the three collaborators every operation depends on:
Backend — persists file metadata (id, name, mimetype, size, folder, references). Typically Doctrine ORM or a custom SQL backend.Storage — stores the raw bytes (usually a filesystem storage; swap for object storage by implementing the interface).Publisher — turns a stored file into a public URL (symlink or copy strategy, served by your web server).Look first at Xi\Filelib\FileLibrary (the façade), Xi\Filelib\File\File, and the Backend / Storage / Publisher interfaces. The first end-to-end use case is: upload a local file, read metadata, generate a public URL, delete it.
use Xi\Filelib\FileLibrary;
$filelib = new FileLibrary($backend, $storage);
// attach publisher + plugins during bootstrap (see below)
$file = $filelib->uploadFile('/tmp/photo.jpg');
echo $file->getId();
echo $file->getName();
echo $file->getMimetype();
echo $filelib->getPublisher()->getUrl($file);
FileLibrary (or a thin FileService around it) into controllers/commands; don't let the raw library leak into domain code. This keeps the upgrade/swap path open, which matters for an unmaintained package.Storage to move bytes to S3/GCS without touching metadata. Keep the Backend as the single source of truth for id/name/mimetype/folder.FileReference over full File in hot paths. References carry just the identity and resolve lazily — useful for lists, pagination, and templates that only need a URL.Storage plus an in-memory/stub Backend; the library is easy to test this way, and it keeps integration tests fast.A typical bootstrap order:
$filelib = new FileLibrary($backend, $storage);
$filelib->setPublisher($publisher); // via config/plugin, depending on version
$filelib->addPlugin(new ImagePlugin(...));
$filelib->addPlugin(new VersionPlugin(...));
getUrl() output against ls -l on the link.Storage and public URLs via Publisher; backend-supplied names may be normalized, hashed, or sharded.FileReference avoids hydration but may re-query on every method call — cache resolved files if you loop.Backend, Storage, Publisher, or Plugin to adapt to your DB, cloud bucket, CDN, or watermarking rules — no forking required.NOASSERTION on GitHub; verify the actual terms in the repo before shipping in a commercial codebase.How can I help you explore Laravel packages today?