php扩展谷歌JsonNet发布

就在昨天,六一儿童节,云智慧高级架构师Neeke把支持谷歌的JsonNet的php扩展模块封装开源了!
 
简单语法改进
Input (Jsonnet)
{
cocktails: {
// Ingredient quantities are in fluid ounces.
"Tom Collins": {
ingredients: [
{ kind: "Farmers Gin", qty: 1.5 },
{ kind: "Lemon", qty: 1 },
{ kind: "Simple Syrup", qty: 0.5 },
{ kind: "Soda", qty: 2 },
{ kind: "Angostura", qty: "dash" },
],
garnish: "Maraschino Cherry",
served: "Tall",
},
Manhattan: {
ingredients: [
{ kind: "Rye", qty: 2.5 },
{ kind: "Sweet Red Vermouth", qty: 1 },
{ kind: "Angostura", qty: "dash" },
],
garnish: "Maraschino Cherry",
served: "Straight Up",
},
}
}
Output (JSON)
{
"cocktails": {

"Tom Collins": {
"ingredients": [
{ "kind": "Farmers Gin", "qty": 1.5 },
{ "kind": "Lemon", "qty": 1 },
{ "kind": "Simple Syrup", "qty": 0.5 },
{ "kind": "Soda", "qty": 2 },
{ "kind": "Angostura", "qty": "dash" }
],
"garnish": "Maraschino Cherry",
"served": "Tall"
},
"Manhattan": {
"ingredients": [
{ "kind": "Rye", "qty": 2.5 },
{ "kind": "Sweet Red Vermouth", "qty": 1 },
{ "kind": "Angostura", "qty": "dash" }
],
"garnish": "Maraschino Cherry",
"served": "Straight Up"
}
}
}
Demo of PHP
    JsonNet::evaluateFile('bar_menu.1.jsonnet');

$Snippet = '
{
cocktails: {
// Ingredient quantities are in fluid ounces.
"Tom Collins": {
ingredients: [
{ kind: "Farmers Gin", qty: 1.5 },
{ kind: "Lemon", qty: 1 },
{ kind: "Simple Syrup", qty: 0.5 },
{ kind: "Soda", qty: 2 },
{ kind: "Angostura", qty: "dash" },
],
garnish: "Maraschino Cherry",
served: "Tall",
},
Manhattan: {
ingredients: [
{ kind: "Rye", qty: 2.5 },
{ kind: "Sweet Red Vermouth", qty: 1 },
{ kind: "Angostura", qty: "dash" },
],
garnish: "Maraschino Cherry",
served: "Straight Up",
},
}
}
';

var_dump(JsonNet::evaluateSnippet($Snippet));
安装请参考我的实践文章:http://www.openskill.cn/article/373
 
项目地址

Github:https://github.com/Neeke/Jsonnet-PHP
Pecl:  http://pecl.php.net/package/jsonnet 
Gitosc:  http://git.oschina.net/ciogao/Jsonnet-PHP


0 个评论

要回复文章请先登录注册