1<?php
2/**
3 * pfcjson.class.php
4 *
5 * Copyright © 2006 Stephane Gully <stephane.gully@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, 51 Franklin St, Fifth Floor,
20 * Boston, MA  02110-1301  USA
21 */
22
23class pfcJSON
24{
25  var $json = null;
26
27  function pfcJSON()
28  {
29    // if the php5-json module is not available, use a software json implementation
30    if (!function_exists('json_encode')) {
31      if (!class_exists('Services_JSON'))
32        require_once(dirname(__FILE__)."/../lib/json/JSON.php");
33      $this->json = new Services_JSON();
34    }
35  }
36
37  function encode($v)
38  {
39    if ($this->json)
40      return $this->json->encode($v);
41    else
42      return json_encode($v);
43  }
44
45  function decode($v)
46  {
47    if ($this->json)
48      return $this->json->decode($v);
49    else
50      return json_decode($v);
51  }
52}
53
54?>