<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Jsonnet-PHPJsonnet 的 PHP 擴展

          聯(lián)合創(chuàng)作 · 2023-09-21 20:36

          JsonNet-PHP 是 Google Jsonnet 對 PHP的支持?jǐn)U展.

          pecl:  http://pecl.php.net/package/jsonnet

          github:  https://github.com/Neeke/Jsonnet-PHP

          gitee: https://gitee.com/neeke/Jsonnet-PHP

          Google Jsonnet Tutorial

          jsonnet語言,使用其提供的基本函數(shù)功能,擁有了強大的對象模型,可以從混合的描述中描繪出對象。這些例子都是有趣的,雖然有點不自然,請不要從現(xiàn)有的例子來限制我們的思維,或以為jsonnet只能作這些特定的應(yīng)用。

          注意:注意jsonnet unparses JSON的一種簡單方法。特別是,它按字母順序排序的輸出對象領(lǐng)域。這是自然的和兼容的JSON,因為如果順序是有意義的,對一個數(shù)組應(yīng)該用來代替一個物體。同時,unparsing JSON使用規(guī)范排序的字段名可以使用diff比較輸出。然而,例如輸出本頁已被手動重新排序,以允許更容易的視覺對比給定輸入。輸出的空格也被調(diào)整以使它更適合放在頁面。

          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  [ [email protected] ] }
            }
          
            - 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 [  public method __construct ] {
                  }
          
                  Method [  public method __destruct ] {
                  }
                }
              }
            }
          }

          CodeTips

          <?php
          /**
           * @author [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;
          
          /**
           * @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();
              }
          
          }
          瀏覽 12
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日本黄色片在线观看 | 三级片无码在线播放 | 一区色 | 91香蕉国产 | 亚洲理论电影 |