tobento/app-file-storage

应用文件存储支持。

1.0.4 2024-08-13 14:45 UTC

This package is auto-updated.

Last update: 2024-09-13 14:59:06 UTC


README

应用文件存储支持。

目录

入门

运行此命令添加运行中的应用文件存储项目的最新版本。

composer require tobento/app-file-storage

要求

  • PHP 8.0 或更高版本

文档

应用

如果您使用的是骨架,请查看 应用骨架

您还可以查看 应用 以了解更多关于应用的一般信息。

文件存储启动

文件存储启动执行以下操作

  • 安装和加载文件存储配置文件
  • 根据存储配置文件创建文件存储
use Tobento\App\AppFactory;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\FileStorage\Boot\FileStorage::class);

// Run the app:
$app->run();

您可以通过查看 文件存储服务 了解更多。

文件存储配置

文件存储的配置位于默认应用骨架配置位置下的 app/config/file_storage.php 文件中,您可以在此处指定应用程序的池和缓存。

文件存储使用

您可以通过以下几种方式访问文件存储

使用应用

use Tobento\App\AppFactory;
use Tobento\Service\FileStorage\StoragesInterface;
use Tobento\Service\FileStorage\StorageInterface;

$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\FileStorage\Boot\FileStorage::class);
$app->booting();

$storages = $app->get(StoragesInterface::class);

$defaultStorage = $app->get(StorageInterface::class);

// Run the app:
$app->run();

您可以通过查看 文件存储服务 了解更多。

查看 存储接口 了解更多关于存储的信息。

查看 存储接口 了解更多关于存储的信息。

使用自动装配

您也可以在任何由应用解析的类中请求接口

use Tobento\Service\FileStorage\StoragesInterface;
use Tobento\Service\FileStorage\StorageInterface;

class SomeService
{
    public function __construct(
        protected StoragesInterface $storages,
        protected StorageInterface $storage,
    ) {}
}

鸣谢