{"id":20180592,"url":"https://github.com/ergebnis/front-matter","last_synced_at":"2025-04-10T05:02:27.156Z","repository":{"id":36969272,"uuid":"325346471","full_name":"ergebnis/front-matter","owner":"ergebnis","description":"👀 Provides a composer package with a front-matter parser.","archived":false,"fork":false,"pushed_at":"2024-04-25T06:51:06.000Z","size":2954,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-01T11:41:18.389Z","etag":null,"topics":["front-matter","parser","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ergebnis.png","metadata":{"funding":{"github":["ergebnis","localheinz"]},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-29T17:23:36.000Z","updated_at":"2024-05-07T07:25:34.901Z","dependencies_parsed_at":"2023-10-25T07:26:38.497Z","dependency_job_id":"a7c6d35c-2048-4bd0-a5ac-4faa14ea312a","html_url":"https://github.com/ergebnis/front-matter","commit_stats":{"total_commits":326,"total_committers":3,"mean_commits":"108.66666666666667","dds":"0.21779141104294475","last_synced_commit":"539e45e9e66d5153c771c558132d05c956e2a4f2"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":"ergebnis/php-package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergebnis%2Ffront-matter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergebnis%2Ffront-matter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergebnis%2Ffront-matter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ergebnis%2Ffront-matter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ergebnis","download_url":"https://codeload.github.com/ergebnis/front-matter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161270,"owners_count":21057554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["front-matter","parser","php"],"created_at":"2024-11-14T02:31:56.760Z","updated_at":"2025-04-10T05:02:27.102Z","avatar_url":"https://github.com/ergebnis.png","language":"PHP","funding_links":["https://github.com/sponsors/ergebnis","https://github.com/sponsors/localheinz"],"categories":[],"sub_categories":[],"readme":"# front-matter\n\n[![Integrate](https://github.com/ergebnis/front-matter/workflows/Integrate/badge.svg)](https://github.com/ergebnis/front-matter/actions)\n[![Merge](https://github.com/ergebnis/front-matter/workflows/Merge/badge.svg)](https://github.com/ergebnis/front-matter/actions)\n[![Release](https://github.com/ergebnis/front-matter/workflows/Release/badge.svg)](https://github.com/ergebnis/front-matter/actions)\n[![Renew](https://github.com/ergebnis/front-matter/workflows/Renew/badge.svg)](https://github.com/ergebnis/front-matter/actions)\n\n[![Code Coverage](https://codecov.io/gh/ergebnis/front-matter/branch/main/graph/badge.svg)](https://codecov.io/gh/ergebnis/front-matter)\n\n[![Latest Stable Version](https://poser.pugx.org/ergebnis/front-matter/v/stable)](https://packagist.org/packages/ergebnis/front-matter)\n[![Total Downloads](https://poser.pugx.org/ergebnis/front-matter/downloads)](https://packagist.org/packages/ergebnis/front-matter)\n[![Monthly Downloads](http://poser.pugx.org/ergebnis/front-matter/d/monthly)](https://packagist.org/packages/ergebnis/front-matter)\n\nThis project provides a [`composer`](https://getcomposer.org) package with a front matter parser.\n\n## Installation\n\nRun\n\n```sh\ncomposer require ergebnis/front-matter\n```\n\n## Usage\n\nThis packages comes with an [`Ergebnis\\FrontMatter\\Parser`](src/Parser.php) interface and provides the following parsers:\n\n - [`Ergebnis\\FrontMatter\\YamlParser`](#yamlparser)\n\n### `YamlParser`\n\nWith the `YamlParser`, you can test if a `string` has YAML front matter:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\FrontMatter;\n\n$parser = new FrontMatter\\YamlParser();\n\n$unparsedContentWithoutFrontMatter = FrontMatter\\Content::fromString('Hello, how are you today?');\n\n$parser-\u003ehasFrontMatter($unparsedContentWithoutFrontMatter); // false\n\n$unparsedContentWithFrontMatter = FrontMatter\\Content::fromString(\u003c\u003c\u003cTXT\n---\npage:\n  title: \"Hello\"\n  description: \"Good to see you, how can I help you?\"\n---\nTXT);\n\n$parser-\u003ehasFrontMatter($unparsedContentWithFrontMatter); // true\n```\n\nWith the `YamlParser`, you can parse a `string`, regardless of whether it has YAML front matter or not.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Ergebnis\\FrontMatter;\n\n$parser = new FrontMatter\\YamlParser();\n\n$unparsedContentWithoutFrontMatter = FrontMatter\\Content::fromString('Hello, how are you today?');\n\n/** @var FrontMatter\\Parsed $parsedWithoutFrontMatter */\n$parsedWithoutFrontMatter = $parser-\u003eparse($unparsedContentWithoutFrontMatter);\n\n$unparsedContentWithFrontMatter = FrontMatter\\Content::fromString(\u003c\u003c\u003cTXT\n---\npage:\n  title: \"Hello\"\n  description: \"Good to see you, how can I help you?\"\n---\nTXT);\n\n/** @var FrontMatter\\Parsed $parsedWithFrontMatter */\n$parsedWithFrontMatter = $parser-\u003eparse($unparsedContentWithoutFrontMatter);\n\nvar_dump($parsedWithFrontMatter-\u003efrontMatter()-\u003edata()-\u003ehas('page.title')); // true\nvar_dump($parsedWithFrontMatter-\u003efrontMatter()-\u003edata()-\u003eget('page.title')); // \"Hello\"\n```\n\n: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.\n\n: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.\n\n## Changelog\n\nThe maintainers of this project record notable changes to this project in a [changelog](CHANGELOG.md).\n\n## Contributing\n\nThe maintainers of this project suggest following the [contribution guide](.github/CONTRIBUTING.md).\n\n## Code of Conduct\n\nThe maintainers of this project ask contributors to follow the [code of conduct](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md).\n\n## General Support Policy\n\nThe maintainers of this project provide limited support.\n\nYou 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).\n\n## PHP Version Support Policy\n\nThis project supports PHP versions with [active and security support](https://www.php.net/supported-versions.php).\n\nThe 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.\n\n## Security Policy\n\nThis project has a [security policy](.github/SECURITY.md).\n\n## License\n\nThis project uses the [MIT license](LICENSE.md).\n\n## Credits\n\nThis project is inspired by [`webuni/front-matter`](https://github.com/webuni/front-matter), originally licensed under MIT by [Martin Hasoň](https://github.com/hason).\n\n## Social\n\nFollow [@localheinz](https://twitter.com/intent/follow?screen_name=localheinz) and [@ergebnis](https://twitter.com/intent/follow?screen_name=ergebnis) on Twitter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fergebnis%2Ffront-matter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fergebnis%2Ffront-matter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fergebnis%2Ffront-matter/lists"}