psx / atom
模型类,以类型安全的方式生成Atom规范
v0.1.0
2024-05-10 16:29 UTC
Requires
- php: >=8.1
- psx/record: ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- psx/schema: ^6.0
- symfony/yaml: ^5.0|^6.0|^7.0
- vimeo/psalm: ^5.0
README
关于
此库包含模型类,以类型安全的方式生成Atom规范。这些模型根据TypeSchema规范自动生成(请参阅 typeschema.json)。以下示例显示了如何生成Atom规范:
$person = new Person(); $person->setName('foobar'); $person->setUri('http://foo.com'); $person->setEmail('foo@bar.com'); $text = new Text(); $text->setContent('foobar'); $entry = new Entry(); $entry->setAuthor([$person]); $entry->setContent($text); $entry->setId('https://.com#1'); $entry->setTitle('Star City'); $entry->setPublished(LocalDateTime::from(new \DateTime('Tue, 10 Jun 2003 04:00:00 GMT'))); $atom = new Atom(); $atom->setId('https://.com'); $atom->setTitle('Foo has bar'); $atom->setUpdated(LocalDateTime::from(new \DateTime('Tue, 10 Jun 2003 04:00:00 GMT'))); $atom->setEntry([$entry]); echo json_encode($asyncAPI, JSON_PRETTY_PRINT);
这将生成以下JSON:
{
"id": "http:\/\/localhost.com",
"title": "Foo has bar",
"updated": "2003-06-10T04:00:00Z",
"entry": [
{
"author": [
{
"name": "foobar",
"uri": "http:\/\/foo.com",
"email": "foo@bar.com"
}
],
"content": {
"content": "foobar"
},
"id": "http:\/\/localhost.com#1",
"published": "2003-06-10T04:00:00Z",
"title": "Star City"
}
]
}
贡献
如果您想提出更改建议,请仅更改typeschema.json规范,然后运行php gen.php脚本来重新生成所有模型类。