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
介绍
此包是使用Laravel ORM (Eloquent) 的Flysystem适配器。
在 config\filesystems.php
中添加你的新磁盘如下:
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'] ] ] ];
创建尽可能多的模型,例如:
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']]); } }
创建控制器,例如:
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');
维护
以下是在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;
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。