vdauchy / eloquent-flysystem-adaptor
0.3.2
2021-05-27 12:42 UTC
Requires
- php: ^7.4|^8.0
- illuminate/database: ^8.0
- illuminate/support: ^8.0
- league/flysystem: ^1.1
- ramsey/uuid: ^4.0
- spatie/laravel-package-tools: ^1.4
Requires (Dev)
- ext-ast: *
- infection/infection: ^0.18
- orchestra/testbench: ^6.6
- phan/phan: ^4.0
- phpunit/phpunit: ^9.2
- slevomat/coding-standard: ^6.4
- squizlabs/php_codesniffer: ^3.5
- vdauchy/sql-analyzer: ^0.4
README
Introduction
This package is an Adaptor for Flysystem using Laravel's ORM (Eloquent).
In config\filesystems.php
add your new disk as:
return [ 'disks' => [ /* Name your disk as you wish */ 'my_sql_disk' => [ /* Use 'eloquent' driver that is registered by this package. */ 'driver' => 'eloquent', /* Optional: Set your custom model that extends the base Model to use different tables per disk */ 'model' => CustomContentModel::class, /* Optional: Set a custom callable to generate urls or just overwrite the static method 'getUrl()' */ 'getUrl' => [CustomContentModel::class, 'getSomeCustomUrl'] ] ] ];
Create as many models as you wish like:
use VDauchy\EloquentFlysystemAdaptor\models\Content; class CustomContentModel extends Content { /** * Example of `getUrl` overwrite to generate URLs using the UUID. */ static public function getUrl(string $path, ?array $metadata): string { return route('my.custom.content', ['uuid' => $metadata['uuid']]); } }
Create controllers like:
Route::get('my-custom-content/{uuid}', function (string $uuid) { $content = CustomContentModel::fromUuid($uuid); /* TODO: Add checks for public/private visibility and improve type/mime handling */ return response($content->contents, 200, ['Content-Type' => $content->mimetype]); }) ->where('uuid', '^[a-z0-9\-]{36}$') ->name('my.custom.content');
Maintenance
Here are the steps to develop/test this package using docker:
# Make sure no image with the same tag exists. docker image rm php-cli-eloquent-flysystem-adaptor:latest -f; # Build new image with the expected extensions. docker build . -t php-cli-eloquent-flysystem-adaptor:latest; # Update vendors. docker run \ --volume $(pwd):/usr/src/app \ php-cli-eloquent-flysystem-adaptor:latest \ composer update; # Run unit tests. docker run \ --volume $(pwd):/usr/src/app \ php-cli-eloquent-flysystem-adaptor:latest \ composer unit; # Run static analysis. docker run \ --volume $(pwd):/usr/src/app \ php-cli-eloquent-flysystem-adaptor:latest \ composer lint; # Run style check. docker run \ --volume $(pwd):/usr/src/app \ php-cli-eloquent-flysystem-adaptor:latest \ composer fmt;
License
The MIT License (MIT). Please see License File for more information.