phpro/zf-filesystem

此包已废弃,不再维护。未建议替代包。
此包最新版本(v0.2.2)没有提供许可证信息。

文件系统包装对象

v0.2.2 2016-01-25 11:07 UTC

This package is not auto-updated.

Last update: 2023-06-26 09:38:38 UTC


README

仓库于2020-11-27废弃

由于我们不再内部使用此仓库,现已归档。请随意使用,我们将不再提供任何支持。

zf-filesystem

此模块包含

  • 文件系统操作的包装器
  • 具有特定功能的文件包装器
  • 元数据层,可以查询特定文件元数据,如IPTC、EXIF、XMP等

安装

添加到composer.json

"phpro/zf-filesystem": "~0.2.0"

添加到应用配置

return array(
    'modules' => array(
        'Phpro\\Filesystem',
        // other libs...
    ),
    // Other config
);

配置

将文件config/phpro_filesystem.local.php.dist复制到您的应用程序的自动加载文件夹中。

配置选项

Exiftool

  • 可执行文件:您的机器上exiftool的位置
  • 允许的标签:可以使用exiftool查询的标签。此列表自动生成,但可以手动覆盖。查看config/exiftool-tags.php获取完整列表。

功能

文件系统包装器

此模块将Symfony Filesystem组件添加到ZF2服务管理器中。通过使用FilesystemAwareInterface,服务管理器会自动将文件系统组件添加到您的对象中。

文件包装器

通过实现FileInterface,可以轻松地将文件对象传递到您的应用程序中的自定义对象和服务。已有2种实现可用

  • LocalFile
  • UploadedFile

可以对这些文件对象应用某些功能。例如

  • 可移动的

元数据

此模块提供了一些查询文件元数据的工具。以下元数据提供者可用

通用

  • MD5

图像

  • ExifTool
  • Identify
  • ImageInfo

MD5

MD5元数据工具提供文件的MD5哈希值,是php md5_file()命令的包装器。

用法

$md5 = $serviceLocator->get('Phpro\Filesystem\Metadata\Md5');
$hash = $md5->getMetadataForFile($file, []);

ExifTool

ExifTool元数据工具为exiftool命令提供了一个封装。它可以返回所有数据或指定一个特定的标签。

用法

$exiftool = $serviceLocator->get('Phpro\Filesystem\Metadata\Image\ExifTool');
$meta = $exiftool->getMetadataForFile($file, []);
$meta = $exiftool->getMetadataForFile($file, ['tag' => 'exif']);
$meta = $exiftool->getMetadataForFile($file, ['tag' => 'iptc']);
$meta = $exiftool->getMetadataForFile($file, ['tag' => 'xmp']);

识别

识别元数据工具为ImageMagickidentify命令提供了一个封装。可以请求常规信息或一些扩展配置。扩展配置包括

  • spotColors

用法

$identify = $serviceLocator->get('Phpro\Filesystem\Metadata\Image\Identify');
$meta = $identify->getMetadataForFile($file, []);
$meta = $identify->getMetadataForFile($file, ['extended' => true]);

图像信息

ExifTool元数据工具为php的getImageSize()命令提供了一个封装。可以返回常规数据或常规加扩展数据

用法

$imageInfo = $serviceLocator->get('Phpro\Filesystem\Metadata\Image\ImageInfo');
$meta = $imageInfo->getMetadataForFile($file, []);
$meta = $imageInfo->getMetadataForFile($file, ['extended' => true]);