ergebnis / front-matter
Provides a front matter parser.
Installs: 32 914
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ~8.0.0 || ~8.1.0 || ~8.2.0
- symfony/yaml: ^5.0.0 || ^6.0.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.30.2
- ergebnis/data-provider: ^1.3.0
- ergebnis/license: ^2.1.0
- ergebnis/php-cs-fixer-config: ~5.3.1
- fakerphp/faker: ^1.21.0
- infection/infection: ~0.26.19
- phpunit/phpunit: ^9.6.4
- psalm/plugin-phpunit: ~0.18.4
- rector/rector: ~0.15.18
- vimeo/psalm: ^5.7.7
This package is auto-updated.
Last update: 2023-03-16 06:59:07 UTC
README
Provides a front matter parser.
Installation
Run
composer require ergebnis/front-matter
Usage
This packages comes with an Ergebnis\FrontMatter\Parser
interface and provides the following parsers:
YamlParser
With the YamlParser
, you can test if a string
has YAML front matter:
<?php use Ergebnis\FrontMatter; $parser = new FrontMatter\YamlParser(); $valueWithoutFrontMatter = 'Hello, how are you today?'; $parser->hasFrontMatter($valueWithoutFrontMatter); // false $valueWithFrontMatter = <<<TXT --- page: title: "Hello" description: "Good to see you, how can I help you?" --- TXT; $parser->hasFrontMatter($valueWithFrontMatter); // true
With the YamlParser
, you can parse a string
, regardless of whether it has YAML front matter or not.
<?php use Ergebnis\FrontMatter; $parser = new FrontMatter\YamlParser(); $valueWithoutFrontMatter = 'Hello, how are you today?'; /** @var FrontMatter\Parsed $parsed */ $parsed = $parser->parse($valueWithoutFrontMatter); $valueWithFrontMatter = <<<TXT --- page: title: "Hello" description: "Good to see you, how can I help you?" --- TXT; /** @var FrontMatter\Parsed $parsed */ $parsed = $parser->parse($valueWithoutFrontMatter);
❗ The YamlParser
will throw an Ergebnis\FrontMatter\Exception\FrontMatterCanNotBeParsed
exception when the front matter is invalid YAML and an Ergebnis\FrontMatter\Exception\FrontMatterIsNotAnObject
exception when the front matter does not describe an object.
💡 The YamlParser
returns an Ergebnis\FrontMatter\Parsed
value object on success, regardless of whether the value has front matter or not.
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Credits
This package is inspired by webuni/front-matter
, originally licensed under MIT by Martin Hasoň.
Curious what I am up to?
Follow me on Twitter!