sonrisa/filesystem-component

此包已废弃且不再维护。未建议替代包。

sonrisa框架的文件系统组件。支持PHP5.3及以上版本。

1.0.0 2013-08-15 19:00 UTC

This package is not auto-updated.

Last update: 2018-01-07 08:46:23 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

1. 安装

将以下内容添加到您的 composer.json 文件中

"sonrisa/filesystem-component":"dev-master"

2. 描述

FileSystem组件允许在文件系统中进行文件和目录操作。

支持文件(Gzip和Zip)和文件夹(Zip)的压缩和解压缩。

3. 方法

此组件中所有可用的操作都已分为两种可能的实体,FileFolder

3.1. 文件类

可用方法

  • File::isReadable($filePath);
  • File::isWritable($filePath);
  • File::isHidden($path);
  • File::isLink($path);
  • File::getExtension($filePath);
  • File::getModificationDate($filePath);
  • File::size($filePath, $format = false, $precision = 2);
  • File::exists($filePath);
  • File::read($filePath);
  • File::write($filePath, $data, $mode = null);
  • File::append($filePath, $data);
  • File::chmod($filePath, $mode);
  • File::delete($filePath);
  • File::rename($filePath,$newFileName,$overwrite=false);
  • File::copy($filePath,$newFilePath,$overwrite=false);
  • File::move($filePath,$destinationFolder,$overwrite=false);
  • File::touch($filePath,$time='',$accessTime='');
  • File::gzip($filePath, $newFileName, $overwrite=false, $param="1");
  • File::gunzip ($filePath, $destinationPath,$overwrite=false);
  • File::zip($filePath, $newFileName, $overwrite=false);
  • File::unzip($filePath, $destinationPath, $overwrite=false)
  • File::softSymLink($original, $alias);
  • File::hardSymLink($original, $alias);
  • File::mimeType($path);
  • File::userOwner($path);
  • File::groupOwner($path);

用法

<?php
use \Sonrisa\Component\FileSystem\File as File;

File::copy('hello/world.txt','goodbye/moon.txt');
File::exists('goodbye/moon.txt');

3.2. 文件夹类

可用方法

  • Folder::isReadable($path);
  • Folder::isWritable($path);
  • Folder::isLink($path);
  • Folder::isHidden($path);
  • Folder::getModificationDate($path);
  • Folder::size($filePath, $format = false, $precision = 2);
  • Folder::copy($filePath,$newFilePath,$overwrite=false);
  • Folder::move($filePath,$newFilePath);
  • Folder::exists($path);
  • Folder::create($path);
  • Folder::delete($path);
  • Folder::rename($path,$newName);
  • Folder::touch($path,$time='',$accessTime='');
  • Folder::chmod($path, $mode);
  • Folder::zip($filePath, $newFileName, $overwrite=false);
  • Folder::unzip($filePath, $newFileName, $overwrite=false);
  • Folder::softSymLink($original, $alias);
  • Folder::hardSymLink($original, $alias);
  • Folder::softSymLink($original, $alias);
  • Folder::hardSymLink($original, $alias);

用法

<?php
use \Sonrisa\Component\FileSystem\Folder as Folder;

Folder::softSymLink('path/to/src','source');
Folder::isLink('source');

4. 完全测试。

使用PHPUnit和Travis-CI进行了测试。所有代码都已测试,兼容PHP 5.3至PHP 5.5以及Facebook的PHP虚拟机:HipHop

5. 待办事项

虽然当前类稳定且可用,但最终仍将添加新功能以提供更好的文件系统支持。

  • 利用

  • 添加从文件中获取数据的函数

  • 添加从目录中获取数据的函数

    • 目录中的文件总数。
    • 具有特定类型或扩展名的文件总数。
    • 目录中最大的文件。
    • 目录中最后修改的文件。
    • 按文件大小排序列出所有目录文件。
    • 按修改日期排序列出所有目录文件。
  • 向现有函数添加新功能

    • Folder::copy($path,$destinationPath,$overwrite=false); 添加覆盖标志意味着首先,读取路径中的所有文件,读取目标文件中的所有文件。如果存在冲突,并且 overwrite == false,则抛出异常。

    • Folder::move($path,$destinationPath,$overwrite=false); 添加覆盖标志意味着首先,读取路径中的所有文件,读取目标文件中的所有文件。如果存在冲突,并且 overwrite == false,则抛出异常。

6. 作者

Nil Portugués Calderó