daylerees/kurenai

Multi document parser with metadata support.

2.1.0 2018-07-18 07:52 UTC

This package is not auto-updated.

Last update: 2024-12-21 15:13:52 UTC


README

Kurenai

Kurenai

Build Status Scrutinizer Code Quality Code Coverage Code Climate HHVM Tested

Packagist Version Packagist

Kurenai is a document with metadata parsing library for PHP. It supports a variety of different document content and metadata parsers.

Installation

Kurenai is available on Packagist for Composer.

composer require daylerees/kurenai

Usage

Kurenai documents look like this:

Some form of metadata here.
===
Some form of content here.

A metadata section, and a content section seperated by three equals === signs or more.

Here's an example using JSON for metadata, and Markdown for content.

{
    "title": "Hello world!"
}
===
# Hello World

Well hello there, world!

Formats for metadata and content are interchangable using classes called parsers. First, let's create our parser instance.

$kurenai = new \Kurenai\Parser(
    new \Kurenai\Parsers\Metadata\JsonParser,
    new \Kurenai\Parsers\Content\MarkdownParser
);

In the above example, we're using a JSON metadata parser, and a Markdown content parser. We can now parse a document.

$document = $kurenai->parse('path/to/document.md');

Our documents can have any filename or extension. You can also pass the parse() function the content of a document directly.

The document instance has a few useful methods.

$document->getRaw();

This will fetch the raw document content. Before Kurenai parsed it.

$document->getMetadata();

This will fetch the metadata, parsed into an array.

$document->getContent();

This will get the content of the document, rendered using the provided content parser.

$document->get('foo.bar');

The get() method uses dot-notation to return a metadata value. For example, the above example would be equivalent to fetching $metadata['foo']['bar'].

If the subject can't be found, null will be returned. You can supply a default value as a second parameter to the method.

Metadata Parsers

Content Parsers

Enjoy using Kurenai!