Download the PHP package yuanqing/fi without Composer
On this page you can find all versions of the php package yuanqing/fi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package fi
Short Description Query a collection of text files like a document database in PHP.
License MIT
Homepage https://github.com/yuanqing/fi
Informations about the package fi
Fi.php

Fi lets you query a collection of text files, as if the folder of files were a database (well, almost).
Fi (rhymes with pie) is designed to be used as part of a static site generator.
Super quick start
There is a documented, runnable example you can play with:
There are also tests.
Quick start
Suppose we have organised our text files into neat date-based folders like so:
Each text file contains YAML frontmatter and content. The file 01-foo.md might be something like:
We would query our data directory like so:
Every file that matches the given $filePathFormat is a Document. A Collection, then, is simply an Iterator over a set of Documents:
We can also access a Document directly by index:
Map, filter, sort
Fi also supports map, filter, and sort operations over our Collection of Documents:
Default values
A text file will inherit default values (for fields or content) from any _defaults.md file found in the same directory, or in a parent directory. Defaults are said to cascade; _defaults.md files found further down the file hierarchy will overwrite those higher up the hierarchy.
API
Fi
Fi::query ( string $dataDir, string $filePathFormat [, string $defaultsFileName = '_defaults.md' ] )
Makes a Collection object.
$dataDiris the directory where Fi will look for text files that match the$filePathFormat.$filePathFormatis specified using a Regex-like syntax; see Extract.php.-
$defaultsFileNameis the name of the text file that Fi will look for when resolving defaults.
Collection
map ( callable $callback )
Applies the $callback to each Document in the Collection. Returns the Collection object.
$callbacktakes a single argument of type Document. It must return an object of type Document.
filter ( callable $callback )
Filter out Documents in the Collection using the $callback. Returns the Collection object.
$callbacktakes a single argument of type Document. Return false to exclude that Document from the Collection.
sort ( callable $callback )
Sorts the Collection using the $callback. Returns the Collection object.
$callbacktakes two arguments of type Document. Return1if the first Document argument is to be ordered before the second, else return-1.
sort ( mixed $fieldName [, int $sortOrder = Fi::ASC ] )
Sorts the Collection by the $fieldName in the specified $sortOrder. Returns the Collection object.
$sortOrdermust be eitherFi::ASCorFi::DESC.
toArr ( )
Gets all the Documents in the Collection as an array.
-
Document
getFilePath ( )
Gets the file path of the text file (relative to the $dataDir) that corresponds to the Document.
getFields ( )
Gets all the fields of the Document.
hasField ( mixed $fieldName )
Checks if the Document has a field with the specified $fieldName.
getField ( mixed $fieldName )
Gets the value of the specified $fieldName.
setField ( mixed $fieldName, mixed $fieldValue )
Sets the field with $fieldName to the specified $fieldValue. Returns the Document object.
hasContent ( )
Checks if the Document content is non-empty.
getContent ( )
Gets the Document content.
setContent ( string $content )
Sets the Document content to the specified $content. Returns the Document object.
-
Requirements
Fi requires at least PHP 5.3 or HHVM, and Composer.
Installation
-
Install Composer.
-
Install the Composer package:
- In your PHP file, require the Composer autoloader:
Testing
You need PHPUnit to run the tests: