[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Document/ -> XmlDocument.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Document;
  11  
  12  use Joomla\CMS\Factory as CmsFactory;
  13  
  14  // phpcs:disable PSR1.Files.SideEffects
  15  \defined('JPATH_PLATFORM') or die;
  16  // phpcs:enable PSR1.Files.SideEffects
  17  
  18  /**
  19   * XmlDocument class, provides an easy interface to parse and display XML output
  20   *
  21   * @since  1.7.0
  22   */
  23  class XmlDocument extends Document
  24  {
  25      /**
  26       * Document name
  27       *
  28       * @var    string
  29       * @since  3.0.0
  30       */
  31      protected $name = 'joomla';
  32  
  33      /**
  34       * Flag indicating the document should be downloaded (Content-Disposition = attachment) versus displayed inline
  35       *
  36       * @var    boolean
  37       * @since  3.9.0
  38       */
  39      protected $isDownload = false;
  40  
  41      /**
  42       * Class constructor
  43       *
  44       * @param   array  $options  Associative array of options
  45       *
  46       * @since   1.7.0
  47       */
  48      public function __construct($options = array())
  49      {
  50          parent::__construct($options);
  51  
  52          // Set mime type
  53          $this->_mime = 'application/xml';
  54  
  55          // Set document type
  56          $this->_type = 'xml';
  57      }
  58  
  59      /**
  60       * Render the document.
  61       *
  62       * @param   boolean  $cache   If true, cache the output
  63       * @param   array    $params  Associative array of attributes
  64       *
  65       * @return  string  The rendered data
  66       *
  67       * @since  1.7.0
  68       */
  69      public function render($cache = false, $params = array())
  70      {
  71          parent::render($cache, $params);
  72  
  73          $disposition = $this->isDownload ? 'attachment' : 'inline';
  74  
  75          CmsFactory::getApplication()->setHeader('Content-disposition', $disposition . '; filename="' . $this->getName() . '.xml"', true);
  76  
  77          return $this->getBuffer();
  78      }
  79  
  80      /**
  81       * Returns the document name
  82       *
  83       * @return  string
  84       *
  85       * @since  1.7.0
  86       */
  87      public function getName()
  88      {
  89          return $this->name;
  90      }
  91  
  92      /**
  93       * Sets the document name
  94       *
  95       * @param   string  $name  Document name
  96       *
  97       * @return  XmlDocument instance of $this to allow chaining
  98       *
  99       * @since   1.7.0
 100       */
 101      public function setName($name = 'joomla')
 102      {
 103          $this->name = $name;
 104  
 105          return $this;
 106      }
 107  
 108      /**
 109       * Check if this document is intended for download
 110       *
 111       * @return  string
 112       *
 113       * @since   3.9.0
 114       */
 115      public function isDownload()
 116      {
 117          return $this->isDownload;
 118      }
 119  
 120      /**
 121       * Sets the document's download state
 122       *
 123       * @param   boolean  $download  If true, this document will be downloaded; if false, this document will be displayed inline
 124       *
 125       * @return  XmlDocument instance of $this to allow chaining
 126       *
 127       * @since   3.9.0
 128       */
 129      public function setDownload($download = false)
 130      {
 131          $this->isDownload = $download;
 132  
 133          return $this;
 134      }
 135  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer