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: 0.5.7
  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.     /**
  32.      * use loose typing to decode js objects into php associative arrays
  33.      * @access public
  34.      */
  35.     var $loose_type;
  36.     
  37.     // }}}
  38.     // {{{ constructor
  39.     function HTML_AJAX_Serializer_JSON($use_loose_type = true
  40.     {
  41.         $this->loose_type = (bool) $use_loose_type;
  42.         $this->_jsonext $this->_detect();
  43.         if(!$this->_jsonext{
  44.             $use_loose_type ($this->loose_typeSERVICES_JSON_LOOSE_TYPE : 0;
  45.             $this->_json = new HTML_AJAX_JSON($use_loose_type);
  46.         }
  47.     }
  48.     // }}}
  49.     // {{{ serialize
  50.     /**
  51.      * This function serializes and input passed to it.
  52.      *
  53.      * @access public
  54.      * @param  string $input   The input to serialize.
  55.      * @return string $input   The serialized input.
  56.      */
  57.     function serialize($input
  58.     {
  59.         if($this->_jsonext{
  60.             return json_encode($input);
  61.         else {
  62.             return $this->_json->encode($input);
  63.         }
  64.     }
  65.     // }}}
  66.     // {{{ unserialize
  67.     /**
  68.      * this function unserializes the input passed to it.
  69.      *
  70.      * @access public
  71.      * @param  string $input   The input to unserialize
  72.      * @return string $input   The unserialized input.
  73.      */
  74.     function unserialize($input
  75.     {
  76.         if($this->_jsonext{
  77.             return json_decode($input$this->loose_type);
  78.         else {
  79.             return $this->_json->decode($input);
  80.         }
  81.     }
  82.     // }}}
  83.     // {{{ _detect
  84.     /**
  85.      * detects the loaded extension
  86.      */
  87.     function _detect()
  88.     {
  89.         return extension_loaded('json');
  90.     }
  91.     // }}}
  92. }
  93. // }}}
  94. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  95. ?>

Documentation generated on Mon, 11 Mar 2019 15:59:25 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.