[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Plugin 5 * @subpackage System.Debug 6 * 7 * @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Plugin\System\Debug; 12 13 use DebugBar\HttpDriverInterface; 14 use Joomla\Application\SessionAwareWebApplicationInterface; 15 use Joomla\Application\WebApplicationInterface; 16 use Joomla\CMS\Application\CMSApplicationInterface; 17 use Joomla\CMS\Session\Session; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Joomla HTTP driver for DebugBar 25 * 26 * @since 4.1.5 27 */ 28 final class JoomlaHttpDriver implements HttpDriverInterface 29 { 30 /** 31 * @var CMSApplicationInterface 32 * 33 * @since 4.1.5 34 */ 35 private $app; 36 37 /** 38 * @var Session 39 * 40 * @since 4.1.5 41 */ 42 private $session; 43 44 /** 45 * @var array 46 * 47 * @since 4.1.5 48 */ 49 private $dummySession = []; 50 51 /** 52 * Constructor. 53 * 54 * @param CMSApplicationInterface $app 55 * 56 * @since 4.1.5 57 */ 58 public function __construct(CMSApplicationInterface $app) 59 { 60 $this->app = $app; 61 62 if ($app instanceof SessionAwareWebApplicationInterface) { 63 $this->session = $app->getSession(); 64 } 65 } 66 67 /** 68 * Sets HTTP headers 69 * 70 * @param array $headers 71 * 72 * @since 4.1.5 73 */ 74 public function setHeaders(array $headers) 75 { 76 if ($this->app instanceof WebApplicationInterface) { 77 foreach ($headers as $name => $value) { 78 $this->app->setHeader($name, $value, true); 79 } 80 } 81 } 82 83 /** 84 * Checks if the session is started 85 * 86 * @return boolean 87 * 88 * @since 4.1.5 89 */ 90 public function isSessionStarted() 91 { 92 return $this->session ? $this->session->isStarted() : true; 93 } 94 95 /** 96 * Sets a value in the session 97 * 98 * @param string $name 99 * @param string $value 100 * 101 * @since 4.1.5 102 */ 103 public function setSessionValue($name, $value) 104 { 105 if ($this->session) { 106 $this->session->set($name, $value); 107 } else { 108 $this->dummySession[$name] = $value; 109 } 110 } 111 112 /** 113 * Checks if a value is in the session 114 * 115 * @param string $name 116 * 117 * @return boolean 118 * 119 * @since 4.1.5 120 */ 121 public function hasSessionValue($name) 122 { 123 return $this->session ? $this->session->has($name) : array_key_exists($name, $this->dummySession); 124 } 125 126 /** 127 * Returns a value from the session 128 * 129 * @param string $name 130 * 131 * @return mixed 132 * 133 * @since 4.1.5 134 */ 135 public function getSessionValue($name) 136 { 137 if ($this->session) { 138 return $this->session->get($name); 139 } 140 141 return $this->dummySession[$name] ?? null; 142 } 143 144 /** 145 * Deletes a value from the session 146 * 147 * @param string $name 148 * 149 * @since 4.1.5 150 */ 151 public function deleteSessionValue($name) 152 { 153 if ($this->session) { 154 $this->session->remove($name); 155 } else { 156 unset($this->dummySession[$name]); 157 } 158 } 159 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |