netzmacht/contao-flysystem

此包已被弃用且不再维护。作者建议使用 oneup/flysystem-bundle 包。

此包将 flysystem 文件系统抽象集成到 Contao 中

安装: 22

依赖: 0

建议: 0

安全: 0

星星: 1

关注者: 2

分支: 0

类型:contao-module

1.0.0-beta1 2015-09-26 15:41 UTC

This package is auto-updated.

Last update: 2022-02-01 12:51:39 UTC


README

Build Status Version License Downloads Contao Community Alliance coding standard

此库将 flysystem 文件系统抽象 集成到 Contao。

它为 TL_ROOT 提供了一个完全配置的文件系统服务,并为 Contao 的 Dbafs 提供了一个适配器!

安装

您可以使用 Composer 安装此库。它需要至少 PHP 5.4 和 Contao 3.2。

$ php composer.phar require netzmacht/contao-flysystem:~1.0

功能

  • 整个 Contao 安装的文件系统抽象
  • Dbafs 适配器
  • 元数据缓存

使用方法

访问挂载管理器和默认文件系统

<?php

// First get the mount manager to get the file system.
$manager    = $GLOBALS['container']['flysystem.mount-manager'];
$fileSystem = $manager->getFilesystem('local');

// Alternatively use the FlysystemTrait
class MyContentElement
{
   use Netzmacht\Contao\Flysystem\Integration\FlysystemTrait;
   
   protected function compile()
   {
      $fileSystem = $this->getMountManager()->getFilesystem('local');
   }
}

Dbafs 文件系统

对于 dbafs 文件系统,存在一个独立的文件系统适配器。它允许通过路径或 uuid 获取文件。元数据通过模型详细信息(id、uuid、hash、meta、importantPart)丰富。

在执行文件系统操作时保持 dbafs 同步。

<?php
 
$manager    = $GLOBALS['container']['flysystem.mount-manager'];
$fileSystem = $manager->getFilesystem('dbafs');

// Get file path.
$metadata = $fileSystem->getMetadata('files/path/to/file');

// Get file by binary uuid.
$metadata = $fileSystem->getMetadata($this->multiSRC);

// Get file by binary uuid.
$metadata = $fileSystem->getMetadata(\String::binToUuid($this->multiSRC));

注意:您必须将文件路径作为 Contao 标准添加到上传路径之前。如果您尝试访问上传路径范围之外的文件,您将收到一个 RootViolationException