Jsonnet-PHP v1.3.0 发布,支持 PHP 7 使用 Jsonnet
JsonNet-PHP 是 Google Jsonnet 对 PHP的支持扩展.
pecl: http://pecl.php.net/package/jsonnet
github: https://github.com/Neeke/Jsonnet-PHP
gitee: https://gitee.com/neeke/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 : http://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 [ extension #40 JsonNet version v1.3.0 ] {
- Constants [2] {
Constant [ string JSONNET_PHP_VERSION ] { v1.3.0 }
Constant [ string JSONNET_PHP_AUTHOR ] { Chitao.Gao [ neeke@php.net ] }
}
- Functions {
Function [ function jsonnet_get_version ] {
}
Function [ function jsonnet_get_author ] {
}
}
- Classes [1] {
Class [ class JsonNet ] {
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [4] {
Method [ static public method evaluateFile ] {
- Parameters [1] {
Parameter #0 [ $file_path ]
}
}
Method [ static public method evaluateSnippet ] {
- Parameters [1] {
Parameter #0 [ $snippet_string ]
}
}
Method [ static public method fmtFile ] {
- Parameters [1] {
Parameter #0 [ $file_path ]
}
}
Method [ static public method fmtSnippet ] {
- Parameters [1] {
Parameter #0 [ $snippet_string ]
}
}
}
- Properties [0] {
}
- Methods [2] {
Method [ <internal:jsonnet, ctor="">public method __construct ] {
}
Method [ <internal:jsonnet, dtor="">public method __destruct ] {
}
}
}
}
}
CodeTips
/**
* @author neeke@php.net
* Date: 18/3/29 下午7:51
*/
const JSONNET_PHP_VERSION = 'v1.3.0';
const JSONNET_PHP_AUTHOR = 'neeke@php.net';
const CODE_SUCCESS = 1000;
const CODE_ERROR = 900;
/**
* @return 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
}
/**
* @param $file_path
*
* @return array
* @throws Exception
*/
static public function evaluateFile($file_path)
{
throw new Exception('JsonNet::evaluateFile #error', CODE_ERROR);
return array();
}
/**
* @param $snippet_string
*
* @return array
* @throws Exception
*/
static public function evaluateSnippet($snippet_string)
{
throw new Exception('JsonNet::evaluateSnippet #error', CODE_ERROR);
return array();
}
/**
* @param $file_path
*
* @return array
* @throws Exception
*/
static public function fmtFile($file_path)
{
throw new Exception('JsonNet::fmtFile #error', CODE_ERROR);
return array();
}
/**
* @param $snippet_string
*
* @return array
* @throws Exception
*/
static public function fmtSnippet($snippet_string)
{
throw new Exception('JsonNet::fmtSnippet #error', CODE_ERROR);
return array();
}
}
(编辑:雷林鹏 来源:网络)
Jsonnet-PHP v1.3.0 发布,支持 PHP 7 使用 Jsonnet的更多相关文章
- 阿里云 Serverless 应用引擎(SAE)发布 v1.2.0,支持一键启停、NAS 存储、小规格实例等实用特性
近日,阿里云 Serverless 应用引擎(SAE)发布 v1.2.0版本,新版本实现了以下新功能/新特性: 一键启停开发测试环境:企业开发测试环境一般晚上不常用,长期保有应用实例,闲置浪费很高.使 ...
- yoyogo v1.7.4 发布,支持 grpc v1.3.8 & etcd 3.5.0
YoyoGo (Go语言框架)一个简单.轻量.快速.基于依赖注入的微服务框架( web .grpc ),支持Nacos/Consoul/Etcd/Eureka/k8s /Apollo等 . https ...
- FineUIMvc v1.4.0 发布了(ASP.NET MVC控件库)!
FineUIMvc v1.4.0 已经于 2017-06-30 发布,FineUIMvc 是基于 jQuery 的专业 ASP.NET MVC 控件库,是我们的新产品.由于和 FineUI(专业版)共 ...
- Visual Studio Code 1.0发布,支持中文在内9种语言
Visual Studio Code 1.0发布,支持中文在内的9种语言:Simplified Chinese, Traditional Chinese, French, German, Italia ...
- RapidJSON v1.1.0 发布简介
时隔 15.6 个月,终于发布了一个新版本 v1.1.0. 新版本除了包含了这些日子收集到的无数的小改进及 bug fixes,也有一些新功能.本文尝试从使用者的角度,简单介绍一下这些功能和沿由. P ...
- YoyoGo v1.7.2 发布, 支持 Nacos & Apollo 配置中心
YoyoGo (Go语言框架)一个简单.轻量.快速.基于依赖注入的微服务框架( web .grpc ),支持Nacos/Consoul/Etcd/Eureka/k8s /Apollo等 . https ...
- 项目实战:Qt文件改名工具 v1.2.0(支持递归检索,搜索:模糊匹配,前缀匹配,后缀匹配;重命名:模糊替换,前缀追加,后缀追加)
需求 在整理文件和一些其他头文件的时候,需要对其名称进行整理和修改,此工具很早就应该写了,创业后,非常忙,今天抽空写了一个顺便提供给学习. 工具和源码下载地址 本篇文章的应用包和源码包可在 ...
- AgileConfig 1.6.0 发布 - 支持服务注册与发现
大家好,好久没有输出博文了,一是因为比较忙,另外一个原因是最近主要的精力是在给 AgileConfig 添加一个新的功能:服务注册与发现. 先说说为什么会添加这个功能.我自己的项目是用 Consul ...
- Yearning v1.3.0 发布,Web 端 SQL 审核平台
企业级MYSQL web端 SQL审核平台. Website 官网 www.yearning.io Feature 功能 数据库字典自动生成 SQL查询 查询工单 导出 自动补全,智能提示 查询语句审 ...
随机推荐
- 百度NLP三面
首先,面试官根据项目经验进行提问,主要是自然语言处理相关的问题:然后写代码题,字符串处理和数字运算居多:再者是一些语言基础知识,百度用的linux平台,C++和python居多.下面列出我面试中的一些 ...
- flyweight模式
参考资料 • 维基百科:https://en.wikipedia.org/wiki/Flyweight_pattern • 百度百科:http://baike.baidu.com/link?url=R ...
- HTML5游戏开发系列教程7(译)
原文地址:http://www.script-tutorials.com/html5-game-development-lesson-7/ 今天我们将完成我们第一个完整的游戏--打砖块.这次教程中,将 ...
- Windows server 2003 伪静态配置方法
Windows server 2003 伪静态配置方法 先我们下载Rewrite伪静态组件到服务器,然后解压到D:\Rewrite下,解压后如下图: 提示:ReWrite组件所在目录要有网站所有者 ...
- Delphi锁定鼠标 模拟左右键 静止一会自动隐藏鼠标
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- XE6移动开发环境搭建之IOS篇(2):安装虚拟机(有图有真相)
XE6移动开发环境搭建之IOS篇(2):安装虚拟机(有图有真相) 2014-08-15 22:04 网上能找到的关于Delphi XE系列的移动开发环境的相关文章甚少,本文尽量以详细的内容.傻瓜式的表 ...
- 12.MySQL必知必会之分组数据
本文将介绍如何分组数据,以便能汇总表内容的子集,这涉及两个新SELECT语句子句,分别是 GROUP BY 子句和HAVING子句. 1.1 创建分组 分组是在SELECT语句的GROUP BY子句中 ...
- zabbix 4.0 安装配置
1.安装软件包: 1.安装软件包: yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap ...
- 字符串的最小最大表示法O(n)
以下介绍内容内容转自:http://blog.csdn.net/zy691357966/article/details/39854359 网上看了这篇文章后还是感觉有些地方讲的没有详细的证明所以添加了 ...
- C++ vector 用法
转自http://www.cnblogs.com/wang7/archive/2012/04/27/2474138.html#undefined 在c++中,vector是一个十分有用的容器,下面对这 ...