[ 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) 2018 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\DataCollector; 12 13 use DebugBar\DataCollector\AssetProvider; 14 use Joomla\CMS\Application\AdministratorApplication; 15 use Joomla\CMS\Application\SiteApplication; 16 use Joomla\CMS\Factory; 17 use Joomla\CMS\Uri\Uri; 18 use Joomla\CMS\User\User; 19 use Joomla\Plugin\System\Debug\AbstractDataCollector; 20 use Joomla\Registry\Registry; 21 use Psr\Http\Message\ResponseInterface; 22 23 // phpcs:disable PSR1.Files.SideEffects 24 \defined('_JEXEC') or die; 25 // phpcs:enable PSR1.Files.SideEffects 26 27 /** 28 * InfoDataCollector 29 * 30 * @since 4.0.0 31 */ 32 class InfoCollector extends AbstractDataCollector implements AssetProvider 33 { 34 /** 35 * Collector name. 36 * 37 * @var string 38 * @since 4.0.0 39 */ 40 private $name = 'info'; 41 42 /** 43 * Request ID. 44 * 45 * @var string 46 * @since 4.0.0 47 */ 48 private $requestId; 49 50 /** 51 * InfoDataCollector constructor. 52 * 53 * @param Registry $params Parameters 54 * @param string $requestId Request ID 55 * 56 * @since 4.0.0 57 */ 58 public function __construct(Registry $params, $requestId) 59 { 60 $this->requestId = $requestId; 61 62 parent::__construct($params); 63 } 64 65 /** 66 * Returns the unique name of the collector 67 * 68 * @since 4.0.0 69 * @return string 70 */ 71 public function getName(): string 72 { 73 return $this->name; 74 } 75 76 /** 77 * Returns a hash where keys are control names and their values 78 * an array of options as defined in {@see \DebugBar\JavascriptRenderer::addControl()} 79 * 80 * @since 4.0.0 81 * @return array 82 */ 83 public function getWidgets(): array 84 { 85 return [ 86 'info' => [ 87 'icon' => 'info-circle', 88 'title' => 'J! Info', 89 'widget' => 'PhpDebugBar.Widgets.InfoWidget', 90 'map' => $this->name, 91 'default' => '{}', 92 ], 93 ]; 94 } 95 96 /** 97 * Returns an array with the following keys: 98 * - base_path 99 * - base_url 100 * - css: an array of filenames 101 * - js: an array of filenames 102 * 103 * @since 4.0.0 104 * @return array 105 */ 106 public function getAssets(): array 107 { 108 return [ 109 'js' => Uri::root(true) . '/media/plg_system_debug/widgets/info/widget.min.js', 110 'css' => Uri::root(true) . '/media/plg_system_debug/widgets/info/widget.min.css', 111 ]; 112 } 113 114 /** 115 * Called by the DebugBar when data needs to be collected 116 * 117 * @since 4.0.0 118 * 119 * @return array Collected data 120 */ 121 public function collect(): array 122 { 123 /** @type SiteApplication|AdministratorApplication $application */ 124 $application = Factory::getApplication(); 125 126 $model = $application->bootComponent('com_admin') 127 ->getMVCFactory()->createModel('Sysinfo', 'Administrator'); 128 129 return [ 130 'phpVersion' => PHP_VERSION, 131 'joomlaVersion' => JVERSION, 132 'requestId' => $this->requestId, 133 'identity' => $this->getIdentityInfo($application->getIdentity()), 134 'response' => $this->getResponseInfo($application->getResponse()), 135 'template' => $this->getTemplateInfo($application->getTemplate(true)), 136 'database' => $this->getDatabaseInfo($model->getInfo()), 137 ]; 138 } 139 140 /** 141 * Get Identity info. 142 * 143 * @param User $identity The identity. 144 * 145 * @since 4.0.0 146 * 147 * @return array 148 */ 149 private function getIdentityInfo(User $identity): array 150 { 151 if (!$identity->id) { 152 return ['type' => 'guest']; 153 } 154 155 return [ 156 'type' => 'user', 157 'id' => $identity->id, 158 'name' => $identity->name, 159 'username' => $identity->username, 160 ]; 161 } 162 163 /** 164 * Get response info. 165 * 166 * @param ResponseInterface $response The response. 167 * 168 * @since 4.0.0 169 * 170 * @return array 171 */ 172 private function getResponseInfo(ResponseInterface $response): array 173 { 174 return [ 175 'status_code' => $response->getStatusCode(), 176 ]; 177 } 178 179 /** 180 * Get template info. 181 * 182 * @param object $template The template. 183 * 184 * @since 4.0.0 185 * 186 * @return array 187 */ 188 private function getTemplateInfo($template): array 189 { 190 return [ 191 'template' => $template->template ?? '', 192 'home' => $template->home ?? '', 193 'id' => $template->id ?? '', 194 ]; 195 } 196 197 /** 198 * Get database info. 199 * 200 * @param array $info General information. 201 * 202 * @since 4.0.0 203 * 204 * @return array 205 */ 206 private function getDatabaseInfo(array $info): array 207 { 208 return [ 209 'dbserver' => $info['dbserver'] ?? '', 210 'dbversion' => $info['dbversion'] ?? '', 211 'dbcollation' => $info['dbcollation'] ?? '', 212 'dbconnectioncollation' => $info['dbconnectioncollation'] ?? '', 213 'dbconnectionencryption' => $info['dbconnectionencryption'] ?? '', 214 'dbconnencryptsupported' => $info['dbconnencryptsupported'] ?? '', 215 ]; 216 } 217 }
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 |