2017 © Pedro Peláez
 

library plum-file

Additional converters and file to work with files in Plum.

image

plumphp/plum-file

Additional converters and file to work with files in Plum.

  • Sunday, October 25, 2015
  • by florianeckerstorfer
  • Repository
  • 1 Watchers
  • 3 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Plum

PlumFile includes converters and filters to work with files in Plum. Plum is a data processing pipeline for PHP., (*1)

Build Status Windows Build status Scrutinizer Code Quality Code Coverage StyleCI, (*2)

Developed by Florian Eckerstorfer in Vienna, Europe., (*3)

Installation

You can install Plum using Composer., (*4)

$ composer require plumphp/plum-file

Usage

Please refer to the Plum documentation for more information about Plum in general., (*5)

FileExtensionFilter

Plum\PlumFile\FileExtensionFilter checks if the file extension of a file name matches., (*6)

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., (*7)

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., (*8)

$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., (*9)

ModificationTimeFilter

The Plum\PlumFile\ModificationTimeFilter returns if a file was modified before and/or after a certain time., (*10)

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., (*11)

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., (*12)

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., (*13)

The Versions

25/10 2015

dev-master

9999999-dev

Additional converters and file to work with files in Plum.

  Sources   Download

MIT

The Requires

 

The Development Requires

file export import plum

28/04 2015

0.2.x-dev

0.2.9999999.9999999-dev

Additional converters and file to work with files in Plum.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2015

v0.2.1

0.2.1.0

Additional converters and file to work with files in Plum.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/04 2015

v0.2

0.2.0.0

Additional converters and file to work with files in Plum.

  Sources   Download

MIT

The Requires

 

The Development Requires

18/03 2015

0.1.x-dev

0.1.9999999.9999999-dev

Additional converters and file to work with files in Plum.

  Sources   Download

MIT

The Requires

 

The Development Requires

18/03 2015

v0.1

0.1.0.0

Additional converters and file to work with files in Plum.

  Sources   Download

MIT

The Requires

 

The Development Requires