yiisoft/yii-filesystem 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

yiisoft/yii-filesystem

Composer 安装命令:

composer require yiisoft/yii-filesystem

包简介

yii-filesystem

README 文档

README

This package is deprecated. Use https://flysystem.thephpleague.com/ directly.

68747470733a2f2f796969736f66742e6769746875622e696f2f646f63732f696d616765732f7969695f6c6f676f2e737667

Yii filesystem


An abstract filesystem that allows to swap underlying file system without rewriting application code. Based on Flysystem.

Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

Requirements

The package requires PHP 8.0 and is meant to be used with Yii3.

Installation

composer require yiisoft/yii-filesystem

After installation, the Yiisoft\Yii\Filesystem\FilesystemInterface will be automatically registered in the main application container. This interface provides a local filesystem with root, as defined in the @root alias of the aliases parameter.

Getting started

The service could be obtained via DI container autowiring:

public function view(\Yiisoft\Yii\Filesystem\FilesystemInterface $filesystem)
{
    $someFileContent = $filesystem->read('/runtime/somefile.txt');
    //...
}

Also you can use aliases

$someFileContent = $filesystem->write('@views/site/testfile.txt', 'Test content');

Configuration

Additional filesystems could be configured in config/params.php as described below:

'file.storage' => [
    'runtimeStorage' => [
        'adapter' => [
            'class' => \League\Flysystem\Local\LocalFilesystemAdapter::class,
            '__construct()' => [
                dirname(__DIR__) . '/runtime',
                \League\Flysystem\UnixVisibility\PortableVisibilityConverter::fromArray([
                    'file' => [
                        'public' => 0644,
                        'private' => 0600,
                    ],
                    'dir' => [
                        'public' => 0755,
                        'private' => 0700,
                    ],
                ]),
                LOCK_EX,
                \League\Flysystem\Local\LocalFilesystemAdapter::DISALLOW_LINKS
            ]
        ],
        'aliases' => [
            '@cache' => '@root/cache',
        ]
    ],
    'documentStorage' => [
        'adapter' => [
            'class' => \League\Flysystem\Local\LocalFilesystemAdapter::class,
            '__construct()' => [
                dirname(__DIR__) . '/docs',
                \League\Flysystem\UnixVisibility\PortableVisibilityConverter::fromArray([
                    'file' => [
                        'public' => 0644,
                        'private' => 0600,
                        ],
                    'dir' => [
                        'public' => 0755,
                        'private' => 0700,
                        ],
                    ]),
                    LOCK_EX,
                    \League\Flysystem\Local\LocalFilesystemAdapter::DISALLOW_LINKS
                ]
        ],
        'aliases' => [
             '@invoices' => '@root/export/invoices',
             '@orders' => '@root/export/orders',
        ],
    ],
],

Aliases runtimeStorage and documentStorage will be automatically registered in the main application container. So, you can get it from the container:

public function index(ContainerInterface $container) 
{
    $documentStorage = $container->get('documentStorage');
}

If you prefer to use autowiring, you can create own interface for your filesystem.

interface ImageStorageInterface extends \Yiisoft\Yii\Filesystem\FilesystemInterface
{
}

And then register it in the params:

'file.storage' => [
    ImageStorageInterface::class => [
        'adapter' => [
            'class' => \League\Flysystem\Local\LocalFilesystemAdapter::class,
            '__construct()' => [
                dirname(__DIR__) . '/storage/images',
                \League\Flysystem\UnixVisibility\PortableVisibilityConverter::fromArray([
                    'file' => [
                        'public' => 0644,
                        'private' => 0600,
                    ],
                    'dir' => [
                        'public' => 0755,
                        'private' => 0700,
                    ],
                ]),
                LOCK_EX,
                \League\Flysystem\Local\LocalFilesystemAdapter::DISALLOW_LINKS
            ]
        ],
    ],
]

Now you can use it like this:

//controller action
public function addImage(ImageStorageInterface $imageStorage)
{
    //get image stream...

    $imageStorage->writeStream('/path/to/image/myimage.jpeg', $myImageStream);
}

You can find documentation on FilesystemInterface methods in the Flysystem Docs.

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework. To run it:

./vendor/bin/infection

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

License

The Yii filesystem is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

统计信息

  • 总下载量: 73.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 11
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-03-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固