vdauchy/eloquent-flysystem-adaptor

0.3.2 2021-05-27 12:42 UTC

This package is auto-updated.

Last update: 2024-09-29 05:49:49 UTC


README

Build Status Total Downloads Latest Stable Version License

介绍

此包是使用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)。有关更多信息,请参阅许可证文件