Skip to content

Latest commit

 

History

History
88 lines (67 loc) · 1.43 KB

README.md

File metadata and controls

88 lines (67 loc) · 1.43 KB

PhiO: Object-oriented filesystem library for PHP

Install

Install via Composer.

composer require amekusa/phio

Examples

Assumed directory structure:

/
└── srv
    └── http
        ├── favicon.svg
        ├── index.html
        ├── script.js
        └── style.css

Iterate over files in a directory

use amekusa\phio\Directory;

$dir = new Directory('/srv/http');
foreach ($dir as $file) {
	echo $file->getPath() . "\n";
}

This code results:

/srv/http/favicon.svg
/srv/http/index.html
/srv/http/script.js
/srv/http/style.css

Filter files

use amekusa\phio\Directory;
use amekusa\phio\Filter;

$dir = new Directory('/srv/http');
$dir->addFilter(new Filter('s*.*s'));

foreach ($dir as $file) {
	echo $file->getPath() . "\n";
}

This code results:

/srv/http/script.js
/srv/http/style.css

You can also use regular expression like this:

use amekusa\phio\Directory;
use amekusa\phio\RegexFilter;

$dir = new Directory('/srv/http');
$dir->addFilter(new RegexFilter('/\.[a-z]{3}$/'));

foreach ($dir as $file) {
	echo $file->getPath() . "\n";
}

This code results:

/srv/http/favicon.svg
/srv/http/style.css