tc/front-matter
Composer 安装命令:
composer require tc/front-matter
包简介
An adapter based front matter parser/dumper for php
README 文档
README
An adapter based front matter parser/dumper for php
Installation
composer require tc/front-matter
Adapters
- YAML
- JSON
Example Usage
<?php use Tc\FrontMatter\FrontMatter; use Tc\FrontMatter\Adapter\JsonAdapter; // sample yaml front matter $fileContent = '--- title: A Title slug: a-slug created: 2017-01-01 12:00 --- This is some sample content '; // create a new parser/dumper $frontMatter = new FrontMatter(); // parse file contents $document = $frontMatter->parse($fileContent); // get data $document->getData(); // get content $document->getContent(); // dump the document back to front matter string $dump = $frontMatter->dumpDocument($document); // dump data and content back to front matter string $dump = $frontMatter->dump(['foo' => 'bar'], 'Hello World'); // parse JSON front matter $jsonAdapter = new JsonAdapter(); // create new parser/dumper using the json adaptor $frontMatter = new FrontMatter($jsonAdapter); // sample json front matter $fileContent = '--- { "title": "A Title", "slug": "a-slug", "created": "2017-01-01 12:00" } --- This is some sample content '; // parse file contents $document = $frontMatter->parse($fileContent);
Symfony Integration
To enable symfony integration add the bundle to your kernel
new Tc\FrontMatter\Bridge\Symfony\TcFrontMatterBundle(),
Now you have access to the front matter service's:
- YAML
tc.front_matterortc.front_matter.yaml - JSON
tc.front_matter.json
Example:
<?php namespace AppBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DefaultController extends Controller { public function indexAction() { $file = file_get_contents('./path/to/front-matter-file'); $document = $this->get('tc.front_matter')->parse($file); return $this->render('default/index.html.twig', [ 'content' => $document->getContent(), 'data' => $document->getData() ]); } }
Custom Adapters
You can create your own custom adapters to parse and dump front matter.
All you need to do is implement Tc\FrontMatter\Adapter\AdapterInterface
You can then create a new instance of front matter using your adapter. e.g.
<?php $myFrontMatter = new FrontMatter(new FooAdapter());
If you are using symfony you can register your adapters as a service, and tag them. e.g.
foo_adapter:
class: 'AppBundle\Adapter\FooAdapter'
tags:
- {name: tc.front_matter.adapter, adapter_name: foo}
The front matter bundle will then auto generate a front matter service for you: tc.front_matter.foo
License
Tc Front Matter is licensed with the MIT license.
See LICENSE for more details.
tc/front-matter 适用场景与选型建议
tc/front-matter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yaml」 「json」 「dump」 「parse」 「front」 「front-matter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tc/front-matter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tc/front-matter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tc/front-matter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package will add the `dd` and `dump` helpers to your Phalcon application.
Simple Twig extension improving templates debugging
nice output for debug functions for PHP 5.3
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-04