Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kherge-archive/php-file-locator

A simple file locator library.
https://github.com/kherge-archive/php-file-locator

Last synced: about 2 months ago
JSON representation

A simple file locator library.

Awesome Lists containing this project

README

        

File Locator
============

[![Build Status](https://travis-ci.org/herrera-io/php-file-locator.png)](http://travis-ci.org/herrera-io/php-file-locator)

A simple file locator library.

Summary
-------

The **FileLocator** library was created to provide file locating capabilities to a larger project. It can be used in templating engines, configuration file loaders, and more.

Installation
------------

Add it to your list of Composer dependencies:

```sh
$ composer require herrera-io/file-locator=1.*
```

Usage
-----

The library includes `FileSystemLocator`, which can be used to search one or more directory paths. Either a single directory path, or an array of paths may be passed to the constructor.

```php
locate('file.ini'); // return the first "file.ini" found
$files = $locator->locate('file.ini', false); // find all named "file.ini"
```

You can also create your own custom file locator by implementing the interface, `LocatorInterface`. All locator classes bundled in the library also implement this interface, allowing drop-in replacement.

```php
add(new FileSystemLocator('/path/to/dir'));
$locators->add(new CustomLocator());

$file = $locator->locate('file.ini'); // return the first "file.ini" found
$files = $locator->locate('file.ini', false); // find all named "file.ini"
```