Source for file json.php

Documentation is available at json.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Document
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * JDocumentJSON class, provides an easy interface to parse and display JSON output
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Document
  17.  * @see         http://www.json.org/
  18.  * @since       11.1
  19.  */
  20. class JDocumentJSON extends JDocument
  21. {
  22.     /**
  23.      * Document name
  24.      *
  25.      * @var    string 
  26.      * @since  11.1
  27.      */
  28.     protected $_name = 'joomla';
  29.  
  30.     /**
  31.      * Class constructor
  32.      *
  33.      * @param   array  $options  Associative array of options
  34.      *
  35.      * @since  11.1
  36.      */
  37.     public function __construct($options array())
  38.     {
  39.         parent::__construct($options);
  40.  
  41.         // Set mime type
  42.         $this->_mime = 'application/json';
  43.  
  44.         // Set document type
  45.         $this->_type = 'json';
  46.     }
  47.  
  48.     /**
  49.      * Render the document.
  50.      *
  51.      * @param   boolean  $cache   If true, cache the output
  52.      * @param   array    $params  Associative array of attributes
  53.      *
  54.      * @return  The rendered data
  55.      *
  56.      * @since  11.1
  57.      */
  58.     public function render($cache false$params array())
  59.     {
  60.         $app JFactory::getApplication();
  61.  
  62.         $app->allowCache(false);
  63.         $app->setHeader('Content-disposition''attachment; filename="' $this->getName('.json"'true);
  64.  
  65.         parent::render();
  66.  
  67.         return $this->getBuffer();
  68.     }
  69.  
  70.     /**
  71.      * Returns the document name
  72.      *
  73.      * @return  string 
  74.      *
  75.      * @since  11.1
  76.      */
  77.     public function getName()
  78.     {
  79.         return $this->_name;
  80.     }
  81.  
  82.     /**
  83.      * Sets the document name
  84.      *
  85.      * @param   string  $name  Document name
  86.      *
  87.      * @return  JDocumentJSON instance of $this to allow chaining
  88.      *
  89.      * @since   11.1
  90.      */
  91.     public function setName($name 'joomla')
  92.     {
  93.         $this->_name = $name;
  94.  
  95.         return $this;
  96.     }
  97. }

Documentation generated on Tue, 19 Nov 2013 15:06:17 +0100 by phpDocumentor 1.4.3