https://github.com/ergebnis/front-matter
👀 Provides a composer package with a front-matter parser.
https://github.com/ergebnis/front-matter
front-matter parser php
Last synced: 9 months ago
JSON representation
👀 Provides a composer package with a front-matter parser.
- Host: GitHub
- URL: https://github.com/ergebnis/front-matter
- Owner: ergebnis
- License: mit
- Created: 2020-12-29T17:23:36.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-25T06:51:06.000Z (over 1 year ago)
- Last Synced: 2024-05-01T11:41:18.389Z (over 1 year ago)
- Topics: front-matter, parser, php
- Language: PHP
- Size: 2.82 MB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# front-matter
[](https://github.com/ergebnis/front-matter/actions)
[](https://github.com/ergebnis/front-matter/actions)
[](https://github.com/ergebnis/front-matter/actions)
[](https://github.com/ergebnis/front-matter/actions)
[](https://codecov.io/gh/ergebnis/front-matter)
[](https://packagist.org/packages/ergebnis/front-matter)
[](https://packagist.org/packages/ergebnis/front-matter)
[](https://packagist.org/packages/ergebnis/front-matter)
This project provides a [`composer`](https://getcomposer.org) package with a front matter parser.
## Installation
Run
```sh
composer require ergebnis/front-matter
```
## Usage
This packages comes with an [`Ergebnis\FrontMatter\Parser`](src/Parser.php) interface and provides the following parsers:
- [`Ergebnis\FrontMatter\YamlParser`](#yamlparser)
### `YamlParser`
With the `YamlParser`, you can test if a `string` has YAML front matter:
```php
hasFrontMatter($unparsedContentWithoutFrontMatter); // false
$unparsedContentWithFrontMatter = FrontMatter\Content::fromString(<<hasFrontMatter($unparsedContentWithFrontMatter); // true
```
With the `YamlParser`, you can parse a `string`, regardless of whether it has YAML front matter or not.
```php
parse($unparsedContentWithoutFrontMatter);
$unparsedContentWithFrontMatter = FrontMatter\Content::fromString(<<parse($unparsedContentWithoutFrontMatter);
var_dump($parsedWithFrontMatter->frontMatter()->data()->has('page.title')); // true
var_dump($parsedWithFrontMatter->frontMatter()->data()->get('page.title')); // "Hello"
```
:exclamation: The `YamlParser` will throw an [`Ergebnis\FrontMatter\Exception\FrontMatterCanNotBeParsed`](src/Exception/FrontMatterCanNotBeParsed.php) exception when the front matter is invalid YAML and an [`Ergebnis\FrontMatter\Exception\FrontMatterIsNotAnObject`](src/Exception/FrontMatterIsNotAnObject.php) exception when the front matter does not describe an object.
:bulb: The `YamlParser` returns an [`Ergebnis\FrontMatter\Parsed`](src/Parsed.php) value object on success, regardless of whether the value has front matter or not.
## Changelog
The maintainers of this project record notable changes to this project in a [changelog](CHANGELOG.md).
## Contributing
The maintainers of this project suggest following the [contribution guide](.github/CONTRIBUTING.md).
## Code of Conduct
The maintainers of this project ask contributors to follow the [code of conduct](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md).
## General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by [sponsoring @localheinz](https://github.com/sponsors/localheinz) or [requesting an invoice for services related to this project](mailto:am@localheinz.com?subject=ergebnis/front-matter:%20Requesting%20invoice%20for%20services).
## PHP Version Support Policy
This project supports PHP versions with [active and security support](https://www.php.net/supported-versions.php).
The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.
## Security Policy
This project has a [security policy](.github/SECURITY.md).
## License
This project uses the [MIT license](LICENSE.md).
## Credits
This project is inspired by [`webuni/front-matter`](https://github.com/webuni/front-matter), originally licensed under MIT by [Martin Hasoň](https://github.com/hason).
## Social
Follow [@localheinz](https://twitter.com/intent/follow?screen_name=localheinz) and [@ergebnis](https://twitter.com/intent/follow?screen_name=ergebnis) on Twitter.