[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/Zend/ -> Json.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Json
  17   * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  18   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  19   */
  20  
  21  
  22  /**
  23   * Class for encoding to and decoding from JSON.
  24   *
  25   * @category   Zend
  26   * @package    Zend_Json
  27   * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  28   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  29   */
  30  class Zend_Json
  31  {
  32      /**
  33       * How objects should be encoded -- arrays or as StdClass. TYPE_ARRAY is 1
  34       * so that it is a boolean true value, allowing it to be used with
  35       * ext/json's functions.
  36       */
  37      const TYPE_ARRAY  = 1;
  38      const TYPE_OBJECT = 0;
  39  
  40      /**
  41       * @var bool
  42       */
  43      public static $useBuiltinEncoderDecoder = false;
  44  
  45      /**
  46       * Decodes the given $encodedValue string which is
  47       * encoded in the JSON format
  48       *
  49       * Uses ext/json's json_decode if available.
  50       *
  51       * @param string $encodedValue Encoded in JSON format
  52       * @param int $objectDecodeType Optional; flag indicating how to decode
  53       * objects. See {@link ZJsonDecoder::decode()} for details.
  54       * @return mixed
  55       */
  56      public static function decode($encodedValue, $objectDecodeType = Zend_Json::TYPE_ARRAY)
  57      {
  58          if (function_exists('json_decode') && self::$useBuiltinEncoderDecoder !== true) {
  59              return json_decode($encodedValue, $objectDecodeType);
  60          }
  61  
  62          require_once  'include/Zend/Json/Decoder.php';
  63          return Zend_Json_Decoder::decode($encodedValue, $objectDecodeType);
  64      }
  65  
  66  
  67      /**
  68       * Encode the mixed $valueToEncode into the JSON format
  69       *
  70       * Encodes using ext/json's json_encode() if available.
  71       *
  72       * NOTE: Object should not contain cycles; the JSON format
  73       * does not allow object reference.
  74       *
  75       * NOTE: Only public variables will be encoded
  76       *
  77       * @param mixed $valueToEncode
  78       * @param boolean $cycleCheck Optional; whether or not to check for object recursion; off by default
  79       * @return string JSON encoded object
  80       */
  81      public static function encode($valueToEncode, $cycleCheck = false)
  82      {
  83          if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) {
  84              return json_encode($valueToEncode);
  85          }
  86  
  87          require_once  'include/Zend/Json/Encoder.php';
  88          return Zend_Json_Encoder::encode($valueToEncode, $cycleCheck);
  89      }
  90  }
  91  


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1