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的更多相关文章

  1. 阿里云 Serverless 应用引擎(SAE)发布 v1.2.0,支持一键启停、NAS 存储、小规格实例等实用特性

    近日,阿里云 Serverless 应用引擎(SAE)发布 v1.2.0版本,新版本实现了以下新功能/新特性: 一键启停开发测试环境:企业开发测试环境一般晚上不常用,长期保有应用实例,闲置浪费很高.使 ...

  2. yoyogo v1.7.4 发布,支持 grpc v1.3.8 & etcd 3.5.0

    YoyoGo (Go语言框架)一个简单.轻量.快速.基于依赖注入的微服务框架( web .grpc ),支持Nacos/Consoul/Etcd/Eureka/k8s /Apollo等 . https ...

  3. FineUIMvc v1.4.0 发布了(ASP.NET MVC控件库)!

    FineUIMvc v1.4.0 已经于 2017-06-30 发布,FineUIMvc 是基于 jQuery 的专业 ASP.NET MVC 控件库,是我们的新产品.由于和 FineUI(专业版)共 ...

  4. Visual Studio Code 1.0发布,支持中文在内9种语言

    Visual Studio Code 1.0发布,支持中文在内的9种语言:Simplified Chinese, Traditional Chinese, French, German, Italia ...

  5. RapidJSON v1.1.0 发布简介

    时隔 15.6 个月,终于发布了一个新版本 v1.1.0. 新版本除了包含了这些日子收集到的无数的小改进及 bug fixes,也有一些新功能.本文尝试从使用者的角度,简单介绍一下这些功能和沿由. P ...

  6. YoyoGo v1.7.2 发布, 支持 Nacos & Apollo 配置中心

    YoyoGo (Go语言框架)一个简单.轻量.快速.基于依赖注入的微服务框架( web .grpc ),支持Nacos/Consoul/Etcd/Eureka/k8s /Apollo等 . https ...

  7. 项目实战:Qt文件改名工具 v1.2.0(支持递归检索,搜索:模糊匹配,前缀匹配,后缀匹配;重命名:模糊替换,前缀追加,后缀追加)

    需求   在整理文件和一些其他头文件的时候,需要对其名称进行整理和修改,此工具很早就应该写了,创业后,非常忙,今天抽空写了一个顺便提供给学习.   工具和源码下载地址   本篇文章的应用包和源码包可在 ...

  8. AgileConfig 1.6.0 发布 - 支持服务注册与发现

    大家好,好久没有输出博文了,一是因为比较忙,另外一个原因是最近主要的精力是在给 AgileConfig 添加一个新的功能:服务注册与发现. 先说说为什么会添加这个功能.我自己的项目是用 Consul ...

  9. Yearning v1.3.0 发布,Web 端 SQL 审核平台

    企业级MYSQL web端 SQL审核平台. Website 官网 www.yearning.io Feature 功能 数据库字典自动生成 SQL查询 查询工单 导出 自动补全,智能提示 查询语句审 ...

随机推荐

  1. vs中nodejs代码 resharper 提示 ECMAScript2015 Feature. your Current language level is ECMAScript5的解决办法

    问题如图 错误信息:ECMAScript 2015 Feature. your Current language level is: ECMAScript5 解决方法, 打开 Resharper -& ...

  2. Oracle扩容表空间

    1.程序报错,无法进行修改操作,通过日志,看到如下错误 2.通过google查询,问题是表空间文件不够了 "表空间大小(M)",(a.bytes "已使用空间(M)&qu ...

  3. 浅析Spring AOP

    在正常的业务流程中,往往存在着一些业务逻辑,例如安全审计.日志管理,它们存在于每一个业务中,然而却和实际的业务逻辑没有太强的关联关系. 图1 这些逻辑我们称为横切逻辑.如果把横切的逻辑代码写在业务代码 ...

  4. Spring框架第五篇之Spring与AOP

    一.AOP概述 AOP(Aspect Orient Programming),面向切面编程,是面向对象编程OOP的一种补充.面向对象编程是从静态角度考虑程序的结构,而面向切面编程是从动态角度考虑程序运 ...

  5. Xcode控制台命令

    命令 解释 break NUM 在指定的行上设置断点 bt 显示所有的调用栈帧,该命令可用来显示函数的调用顺序 clear 删除设置在特定源文件.特定行上的断点,其用法为:clear FILENAME ...

  6. Winter-2-STL-B Brackets 解题报告及测试数据

    Time Limit:2000MS     Memory Limit:65536KB Description Given a string consisting of brackets of two ...

  7. spray-json

    spray-json是一个轻量级的,简介的和高效的使用Scala实现的json 它拥有以下特征: 一个简单不可变的模型的json语言元素 一个高效的json解析器 可选择既紧凑又漂亮的json到str ...

  8. 20145316许心远《Java程序设计》第4周学习总结

    20145316许心远<Java程序设计>第4周学习总结 教材学习内容总结 6.继承与多态 1.继承共同行为 * 多个类中存在相同属性和行为时,将这些内容抽取到单独一个类中,那么多个类无需 ...

  9. CSS Position(定位)

    CSS Position(定位) 一.CSS Position(定位) position 属性指定了元素的定位类型. position 属性的五个值: static relative fixed ab ...

  10. 照着官网来安装openstack pike之environment设置

    安装openstack前的准备环境: 两个centos7系统的环境:192.168.101.10 node1,192.168.101.11 node2 控制节点node1,计算节点node2 1.统一 ...