定制 plumphp/plum-file 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

plumphp/plum-file

最新稳定版本:v0.2.1

Composer 安装命令:

composer require plumphp/plum-file

包简介

Additional converters and file to work with files in Plum.

README 文档

README

Plum

PlumFile includes converters and filters to work with files in Plum. Plum is a data processing pipeline for PHP.

Build Status Windows Build status Scrutinizer Code Quality Code Coverage StyleCI

Developed by Florian Eckerstorfer in Vienna, Europe.

Installation

You can install Plum using Composer.

$ composer require plumphp/plum-file

Usage

Please refer to the Plum documentation for more information about Plum in general.

FileExtensionFilter

Plum\PlumFile\FileExtensionFilter checks if the file extension of a file name matches.

use Plum\PlumFile\FileExtensionFilter;

$filter = new FileExtensionFilter('md');
$filter->filter('README.md'); // -> true
$filter->filter('README.html'); // -> false

If the item is are more complex structure, for example, an array or an object FileExtensionFilter uses Symfonys PropertyAccess to retrieve the filename from the item. You can pass the path to the property as the second argument to the constructor.

use Plum\PlumFile\FileExtensionFilter;

$filterArray = new FileExtensionFilter('md', '[filename]');
$filterArray->filter(['filename' => 'README.md']); // -> true
$filterArray->filter(['filename' => 'README.html']); // -> false

$item = new stdClass();
$item->filename = 'README.md';
$filterObject = new FileExtensionFilter('md', 'filename');
$filterObject->filter($item); // -> true
$item->filename = 'README.html';
$filterObject->filter($item); // -> false

The extension passed to the constructor can also be an array. The filter returns true if the given item matches any of the extensions in the array.

$filter = new FileExtensionFilter(['md', 'html']);
$filter->filter('file.md');   // -> true
$filter->filter('file.html'); // -> false
$filter->filter('file.csv`);  // -> false

Just like the FileExtensionFilter the ModificationTimeFilter uses the Property Access component to retrieve the filename. You can pass the path to the property as second argument to the constructor. The file can be either a string or an instance of SplFileInfo.

ModificationTimeFilter

The Plum\PlumFile\ModificationTimeFilter returns if a file was modified before and/or after a certain time.

use Plum\PlumFile\ModificationTimeFilter;

$after = new ModificationTimeFilter(['after' => new DateTime('-3 days')]);
$after->filter('modified-2-days-ago.txt'); // -> true
$after->filter('modified-4-days-ago.txt'); // -> false

$before = new ModificationTimeFilter(['before' => new DateTime('-3 days')]);
$before->filter('modified-4-days-ago.txt'); // -> true
$before->filter('modified-2-days-ago.txt'); // -> false

$range = new ModificationTimeFilter(['after' => new DateTime('-6 days'), 'before' => new DateTime('-3 days')]);
$range->filter('modified-4-days-ago.txt'); // -> true
$range->filter('modified-8-days-ago.txt'); // -> false
$range->filter('modified-2-days-ago.txt'); // -> false

FileGetContentsConverter

The Plum\PlumFile\FileGetContentsConverter takes a SplFileInfo object or a filename and returns the content of the file.

use Plum\PlumFile\FileGetContentsConverter;

$converter = new FileGetContentsConverter();
$converter->convert('foo.txt'); // -> 'content of foo.txt'

If the item is a more complex structure it is possible to define the Vale accessor property for both the filename and the content.

use Plum\PlumFile\FileGetContentsConverter;

$converter = new FileGetContentsConverter('file', 'content');
$converter->convert(['file' => foo.txt']);
// -> ['file' => 'foo.txt', 'content' => content of foo.txt']

Change Log

Version 0.2.1 (28 April 2015)

  • Fix Plum version

Version 0.2 (22 April 2015)

  • Set Plum version to 0.2

Version 0.1 (18 March 2015)

  • Initial release

License

The MIT license applies to plumphp/plum-finder. For the full copyright and license information, please view the LICENSE file distributed with this source code.

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-22