承接 uxf/storage 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

uxf/storage

最新稳定版本:3.75.10

Composer 安装命令:

composer require uxf/storage

包简介

README 文档

README

Install

$ composer req uxf/storage

Migration

$this->addSql("
    INSERT INTO uxf_storage.object
    (parent_id, file_id, document_id, name, path, variant, \"order\", deleted, created_at, updated_at, type, locked)
    VALUES
    (NULL, NULL, NULL, '', '/', 'basic', 0, FALSE, NOW(), NOW(), 'folder', TRUE)
");

Config

// config/routes/uxf.php
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function (RoutingConfigurator $routes): void {
    $routes->import('@UXFStorageBundle/config/routes.php');
};
// config/packages/uxf.php
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension('uxf_storage', [
        'filesystems' => [
            'default' => '%env(STORAGE_DSN)%', // default local
        ],
    ]);
};
StorageDSNcomposer
Locallocal://default/%kernel.project_dir%/public/upload
AWS S3aws://key:secret@domain.com/bucketleague/flysystem-async-aws-s3
Azureazure://accountName:accountKey@core.windows.net/containerleague/flysystem-azure-blob-storage
S3s3://key:secret@domain.com/bucket
S3 https3://key:secret@domain.com/bucket?schema=http

Usage

FileCreator

use League\Flysystem\FilesystemOperator;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use UXF\Core\SystemProvider\Uuid;
use UXF\Storage\Entity\File;
use UXF\Storage\Entity\Image;
use UXF\Storage\Utils\DestinationDirHelper;
use UXF\Storage\Utils\MimeTypeHelper;

class UploadedFileCreator implements FileCreator
{
    public function __construct(private readonly FilesystemOperator $defaultFilesystem)
    {
    }

    public function createFile(object $file, ?string $namespace): ?File
    {
        if (!$file instanceof UploadedFile) {
            return null;
        }

        $uuid = Uuid::uuid4();

        $type = $file->getClientMimeType();
        $ext = $file->getClientOriginalExtension();
        $ext = $ext !== '' ? $ext : (MimeTypeHelper::convertToExtension($type) ?? 'jpg');
        $size = $file->getSize();
        $raw = $file->getContent();

        $destDir = DestinationDirHelper::getDir($uuid, $namespace);
        $this->defaultFilesystem->write("$destDir/$uuid.$ext", $file->getContent());

        $originalName = $file->getClientOriginalName();

        if (MimeTypeHelper::isImage($type)) {
            $result = getimagesizefromstring($raw);
            assert($result !== false);
            [$width, $height] = $result;
            return new Image($uuid, $ext, $type, $originalName, $namespace, $size, $width ?? 0, $height ?? 0);
        }

        return new File($uuid, $ext, $type, $originalName, $namespace, $size);
    }
}

统计信息

  • 总下载量: 16.89k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-30