Jsonnet-PHP v1.3.0 发布,支持 PHP 7 使用 Jsonnet

栏目: 软件资讯 发布于: 2018-03-30 12:50:02

彩票公式规律走势 www.dumec.tw JsonNet-PHP 是 Google?Jsonnet?对?PHP的支持扩展.

Change Log:?

1.3.0

- Update Lib JsonNet use v0.10.0.
- Support PHP 7.

1.2.0

- Update Lib JsonNet use v0.9.5.
- Add function JsonNet::fmtFile.
- Add function JsonNet::fmtSnippet.

Google Jsonnet Tutorial

jsonnet语言,为我们最常使用的json对象赋予了新的生命力。使用jsonnet来描述json对象,可以在json对象中方便地使用变量\引用\循环等语法,甚至可以书写业务逻辑。

Install Jsonnet-PHP扩展

The?pecl?package?is?:??//pecl.php.net/package/jsonnet

pecl?install?jsonnet

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));

PHP Re Result

/usr/local/php/php-7.0.6-zts-debug/bin/php?--re?jsonnet

Extension?[?<persistent>?extension?#40?JsonNet?version?v1.3.0?]?{

??-?Constants?[2]?{
????Constant?[?string?JSONNET_PHP_VERSION?]?{?v1.3.0?}
????Constant?[?string?JSONNET_PHP_AUTHOR?]?{?Chitao.Gao??[[email protected]?]?}
??}

??-?Functions?{
????Function?[?<internal:JsonNet>?function?jsonnet_get_version?]?{
????}
????Function?[?<internal:JsonNet>?function?jsonnet_get_author?]?{
????}
??}

??-?Classes?[1]?{
????Class?[?<internal:JsonNet>?class?JsonNet?]?{

??????-?Constants?[0]?{
??????}

??????-?Static?properties?[0]?{
??????}

??????-?Static?methods?[4]?{
????????Method?[?<internal:JsonNet>?static?public?method?evaluateFile?]?{

??????????-?Parameters?[1]?{
????????????Parameter?#0?[?<required>?$file_path?]
??????????}
????????}

????????Method?[?<internal:JsonNet>?static?public?method?evaluateSnippet?]?{

??????????-?Parameters?[1]?{
????????????Parameter?#0?[?<required>?$snippet_string?]
??????????}
????????}

????????Method?[?<internal:JsonNet>?static?public?method?fmtFile?]?{

??????????-?Parameters?[1]?{
????????????Parameter?#0?[?<required>?$file_path?]
??????????}
????????}

????????Method?[?<internal:JsonNet>?static?public?method?fmtSnippet?]?{

??????????-?Parameters?[1]?{
????????????Parameter?#0?[?<required>?$snippet_string?]
??????????}
????????}
??????}

??????-?Properties?[0]?{
??????}

??????-?Methods?[2]?{
????????Method?[?<internal:JsonNet,?ctor>?public?method?__construct?]?{
????????}

????????Method?[?<internal:JsonNet,?dtor>?public?method?__destruct?]?{
????????}
??????}
????}
??}
}

CodeTips

<?php
/**
?*[email protected][email protected]
?*?Date:?18/3/29?下午7:51
?*/

const?JSONNET_PHP_VERSION?=?'v1.3.0';
const?JSONNET_PHP_AUTHOR??=?'[email protected]';

const?CODE_SUCCESS?=?1000;
const?CODE_ERROR???=?900;

/**
?*[email protected]?string
?*/
function?jsonnet_get_version()
{
????return?JSONNET_PHP_VERSION;
}

function?jsonnet_get_author()
{
????return?JSONNET_PHP_AUTHOR;
}

class?JsonNet
{
????public?function?__construct()
????{
????????#JsonNet?init
????}

????public?function?__destruct()
????{
????????#JsonNet?destroy
????}

????/**
?????*[email protected]?$file_path
?????*
?????*[email protected]?array
?????*[email protected]?Exception
?????*/
????static?public?function?evaluateFile($file_path)
????{
????????throw?new?Exception('JsonNet::evaluateFile?#error',?CODE_ERROR);

????????return?array();
????}

????/**
?????*[email protected]?$snippet_string
?????*
?????*[email protected]?array
?????*[email protected]?Exception
?????*/
????static?public?function?evaluateSnippet($snippet_string)
????{
????????throw?new?Exception('JsonNet::evaluateSnippet?#error',?CODE_ERROR);

????????return?array();
????}

????/**
?????*[email protected]?$file_path
?????*
?????*[email protected]?array
?????*[email protected]?Exception
?????*/
????static?public?function?fmtFile($file_path)
????{
????????throw?new?Exception('JsonNet::fmtFile?#error',?CODE_ERROR);

????????return?array();
????}

????/**
?????*[email protected]?$snippet_string
?????*
?????*[email protected]?array
?????*[email protected]?Exception
?????*/
????static?public?function?fmtSnippet($snippet_string)
????{
????????throw?new?Exception('JsonNet::fmtSnippet?#error',?CODE_ERROR);

????????return?array();
????}

}

【声明】文章转载自:开源中国社区 [//www.oschina.net]

本站文章除注明转载外,均为本站原创或编译?;队魏涡问降淖?,但请务必注明出处。
转载请注明:文章转载自 彩票公式规律走势
本文标题:Jsonnet-PHP v1.3.0 发布,支持 PHP 7 使用 Jsonnet
IT技术书籍推荐:
疯狂Android讲义(第3版)
疯狂Android讲义(第3版)
李刚 (作者)
移动互联网已经成为当今世界发展最快、市场潜力最大、前景最诱人的业务,而Android则是移动互联网上市场占有率最高的平台。 本书是《疯狂Android讲义》的第3版,本书基于最新的Android 5,并采用了Google推荐的IDE:Android Studio作为开发工具,书中每个案例、每个截图都全面升级到Android 5。本书全面介绍了Android应用开发的相关知识,全书内容覆盖了Android用户界面编程、Android四大组件、Android资源访问、图形/图像处理、事件处理机制、Android输入/输出处理、音频/视频多媒体应用开发、OpenGL与3D应用开发、网络通信编程、Android平台的Web Service、传感器应用开发、GPS应用开发、整合第三方Map服务等。