kedrigern/phpio

PHP class for batch file processing. You can read, write, delete, move. All in pretty object.

v0.7.1 2014-08-07 21:35 UTC

This package is not auto-updated.

Last update: 2024-12-17 08:48:18 UTC


README

Contains class for manipulation with files. It is simple wrapper over internal functions, but in pretty object form.

Build Status

Examples

We suppose:

$files = new \Kedrigern\phpIO\Files();

Cat all *.txt files and after delete them:

$cat = function($file) {
	echo "Filename: $file \n";
	echo file_get_contents($file);
	echo "\n";
};

$files->dir('*.txt')->call($cat)->delete();

Write "Some data" to all *.txt files and after move them to the directory archive. If files are not writable throw exception with description of problem (exact file, privileges etc.)

$fill = function($file) {
	file_put_contents($file, "Some data.");
};

$files->dir('*.txt')->writeable()->call($fill)->move('archive', true);

Sum numbers from files (with num sufix):

$parseIntFromFile = function($file) {
	return intval(file_get_contents($file));
};

$postSum = function($results) {
	return array_sum($results);
};

$files->dir('*.num')->call($parseIntFromFile, $postSum, $log);

// now $log['post'] contains sum

Install and tests

composer install
vendor/bin/tester -c test/ test/

Authors and contact