2017 © Pedro Peláez
 

library yaml-front-matter

YAML Front-matter Parser/Dumper for PHP

image

kzykhys/yaml-front-matter

YAML Front-matter Parser/Dumper for PHP

  • Wednesday, December 25, 2013
  • by kzykhys
  • Repository
  • 1 Watchers
  • 25 Stars
  • 4,702 Installations
  • PHP
  • 2 Dependents
  • 1 Suggesters
  • 5 Forks
  • 4 Open issues
  • 3 Versions
  • 3 % Grown

The README.md

YAML Front-matter Parser/Dumper for PHP

Latest Stable Version Build Status Coverage Status SensioLabsInsight, (*1)

A PHP YAML Front-matter parser/dumper using symfony/yaml., (*2)

Requirements

  • PHP5.3+

Installation

Create or update your composer.json and run composer update, (*3)

``` json { "require": { "kzykhys/yaml-front-matter": ">=1.0" } }, (*4)


Usage ----- ### FrontMatter::parse(string $input) ``` php <?php require __DIR__ . '/vendor/autoload.php'; use KzykHys\FrontMatter\FrontMatter; // Parse a document $document = FrontMatter::parse(<<<EOF --- title: Hello World category: blog layout: post tags: - technology - PHP vars: pingback_url: http://example.com/pingback?id={{post.id}} description: ~ extra: markdown: gfm: true textile: true template: twig --- {% block content %} Lorem Ipsum ... {% endblock %} EOF ); var_dump($document); // An instance of `Document` var_dump($document->getConfig()); // An array {title:"Hello World", category: "blog"....} var_dump($document->getContent()); // "{% block content %}...." var_dump((string) $document); // "{% block content %}...." var_dump($document["layout"]); // "post" var_dump($document["extra"]["template"]); // "twig" foreach ($document as $key => $value) { var_dump($key, $value); // "title", "Hello World" break; }

FrontMatter::dump(Document $document)

``` php <?php, (*5)

use KzykHys\FrontMatter\Document; use KzykHys\FrontMatter\FrontMatter;, (*6)

require DIR . '/vendor/autoload.php';, (*7)

$document = new Document(); $document['title'] = 'Hello!'; $document['tags'] = array('uncategorized', 'test'); $document->setContent(', (*8)

Hello World!, (*9)

');, (*10)

echo FrontMatter::dump($document);, (*11)


will output:

title: Hello! tags: - uncategorized, (*12)

- test

, (*13)

Hello World!, (*14)


### Document::inherit(Document $parent) ``` php $parent = FrontMatter::parse(<<<EOF --- extra: template: twig category: blog tags: - PHP --- Lorem Ipsum ... EOF ); $document = FrontMatter::parse(<<<EOF --- extra: template: smarty tags: - HHVM - PHP5.5 --- Lorem Ipsum ... EOF ); $document->inherit($parent); var_dump($document->getConfig());
array(2) {
  'extra' => array(1) {
    'template' => string(6) "smarty"
  }
  'category' => string(4) "blog"
  'tags' => array(3) {
    [0] => string(3) "PHP"
    [1] => string(4) "HHVM"
    [2] => string(6) "PHP5.5"
  }
}

License

The MIT License, (*15)

Author

Kazuyuki Hayashi (@kzykhys), (*16)

The Versions

25/12 2013

dev-master

9999999-dev

YAML Front-matter Parser/Dumper for PHP

  Sources   Download

MIT

The Requires

 

by Kazuyuki Hayashi

parser yaml front-matter

25/12 2013

v1.0.1

1.0.1.0

YAML Front-matter Parser/Dumper for PHP

  Sources   Download

MIT

The Requires

 

by Kazuyuki Hayashi

parser yaml front-matter

18/12 2013

v1.0.0

1.0.0.0

YAML Front-matter Parser/Dumper for PHP

  Sources   Download

MIT

The Requires

 

by Kazuyuki Hayashi

parser yaml front-matter