jasir / php-raml-parser
PHP 编写的 RAML 解析器
2.1.1
2016-06-11 08:57 UTC
Requires
- php: >=5.4
- justinrainbow/json-schema: ~1.5
- oodle/inflect: ~0.2
- symfony/routing: ~2.5
- symfony/yaml: ~2.6
Requires (Dev)
- phpunit/phpunit: 4.*
- satooshi/php-coveralls: ~0.6
- squizlabs/php_codesniffer: @dev
README
将 RAML 文件解析成 PHP 对象。
在此处查看 RAML 规范: https://github.com/raml-org/raml-spec
开始使用
要求
- composer (请参阅 https://getcomposer.org.cn)
composer require alecsammon/php-raml-parser --dev
$parser = new \Raml\Parser(); $apiDef = $parser->parse($filename, true); $title = $apiDef->getTitle();
解析模式
库可以将模式转换为验证对象。默认有一个列表,也可以手动配置。每个模式解析器需要符合 \Raml\Schema\SchemaParserInterface
并返回一个 \Raml\Schema\SchemaDefinitionInterface
的实例。
可以创建额外的解析器和模式定义,并将它们传递给 \Raml\Parser
构造函数
导出路由
还可以将整个 RAML 文件导出为包含完整端点的数组。例如,考虑一个 基本的 RAML,这可以通过以下方式返回
$parser = new Raml\Parser(); $api = $parser->parse('test/fixture/simple.raml'); $routes = $api->getResourcesAsUri();
返回
[ GET /songs => ... POST /songs => ... GET /songs/{songId} => ... DELETE /songs/{songId} => ... ] $routes = $api->getResourcesAsUri(new Raml\RouteFormatter\NoRouteFormatter());
路由格式化程序
此包包含两个路由格式化程序
NoRouteFormatter
不做任何事情,仅简单地输出结果SymfonyRouteFormatter
将路由添加到 Symfony 的RouteCollection
贡献
./vendor/bin/phpunit ./vendor/bin/phpunit --coverage-text ./vendor/bin/phpcs --standard=PSR1,PSR2 src
待办事项
- 文档/Markdown 解析器
- 日期表示法?
- 在提供的 URL 上解析 RAML
支持(我相信)
- 包含
- .yml/.yaml
- .raml/.rml
- .json(使用 json-schema 解析)
- 显示名称
- 特性
- 资源类型