AJAX
[ class tree: AJAX ] [ index: AJAX ] [ all elements ]

Source for file JSON.php

Documentation is available at JSON.php

  1. <?php
  2. require_once 'HTML/AJAX/JSON.php';
  3. // $Id$
  4. /**
  5.  * JSON Serializer
  6.  *
  7.  * @category   HTML
  8.  * @package    AJAX
  9.  * @author     Joshua Eichorn <josh@bluga.net>
  10.  * @copyright  2005 Joshua Eichorn
  11.  * @license    http://www.opensource.org/licenses/lgpl-license.php  LGPL
  12.  * @version    Release: @package_version@
  13.  * @link       http://pear.php.net/package/PackageName
  14.  */
  15. // {{{ class HTMLA_AJAX_Serialize_JSON
  16. {
  17.     // {{{ variables-properties
  18.     /**
  19.      * JSON instance
  20.      * @var HTML_AJAX_JSON 
  21.      * @access private
  22.      */
  23.     var $_json;
  24.  
  25.     /**
  26.      * use json php extension http://www.aurore.net/projects/php-json/
  27.      * @access private
  28.      */
  29.     var $_jsonext;
  30.     // }}}
  31.     // {{{ constructor
  32.     function HTML_AJAX_Serializer_JSON(
  33.     {
  34.         $this->_jsonext $this->_detect();
  35.         if(!$this->_jsonext{
  36.             $this->_json =new HTML_AJAX_JSON();
  37.         }
  38.     }
  39.     // }}}
  40.     // {{{ serialize
  41.     /**
  42.      * This function serializes and input passed to it.
  43.      *
  44.      * @access public
  45.      * @param  string $input   The input to serialize.
  46.      * @return string $input   The serialized input.
  47.      */
  48.     function serialize($input
  49.     {
  50.         if($this->_jsonext{
  51.             return json_encode($input);
  52.         else {
  53.             return $this->_json->encode($input);
  54.         }
  55.     }
  56.     // }}}
  57.     // {{{ unserialize
  58.     /**
  59.      * this function unserializes the input passed to it.
  60.      *
  61.      * @access public
  62.      * @param  string $input   The input to unserialize
  63.      * @return string $input   The unserialized input.
  64.      */
  65.     function unserialize($input
  66.     {
  67.         if($this->_jsonext{
  68.             return json_decode($input);
  69.         else {
  70.             return $this->_json->decode($input);
  71.         }
  72.     }
  73.     // }}}
  74.     // {{{ _detect
  75.     /**
  76.      * detcts the loaded extension
  77.      */
  78.     function _detect()
  79.     {
  80.         return extension_loaded('json');
  81.     }
  82.     // }}}
  83. }
  84. // }}}
  85. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  86. ?>

Documentation generated on Mon, 11 Mar 2019 14:38:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.