CoreFiles by mySites.guru
LanguageFilesCollector.php129 lines, 2,498 bytes, from Joomla_4.0.0-beta2-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta
md5
c1d196565c7a32b18f5937553294d9e0
sha1
c3254b63be0ece8665bf92045c676d1675a622e3
sha256
0f965aa9829735734876a51751519c4f84f7575b5d6f1e4e5bd26d35347d4792
<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  System.Debug
 *
 * @copyright   Copyright (C) 2017 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\System\Debug\DataCollector;

use DebugBar\DataCollector\AssetProvider;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\Plugin\System\Debug\AbstractDataCollector;

/**
 * LanguageFilesDataCollector
 *
 * @since  4.0.0
 */
class LanguageFilesCollector extends AbstractDataCollector implements AssetProvider
{
	/**
	 * Collector name.
	 *
	 * @var   string
	 * @since 4.0.0
	 */
	private $name = 'languageFiles';

	/**
	 * The count.
	 *
	 * @var   integer
	 * @since 4.0.0
	 */
	private $count = 0;


	/**
	 * Called by the DebugBar when data needs to be collected
	 *
	 * @since  4.0.0
	 *
	 * @return array Collected data
	 */
	public function collect(): array
	{
		$paths = Factory::getLanguage()->getPaths();
		$loaded = [];

		foreach ($paths as $extension => $files)
		{
			$loaded[$extension] = [];

			foreach ($files as $file => $status)
			{
				$loaded[$extension][$file] = $status;

				if ($status)
				{
					$this->count++;
				}
			}
		}

		return [
			'loaded' => $loaded,
			'xdebugLink' => $this->getXdebugLinkTemplate(),
			'jroot' => JPATH_ROOT,
			'count' => $this->count,
		];
	}

	/**
	 * Returns the unique name of the collector
	 *
	 * @since  4.0.0
	 *
	 * @return string
	 */
	public function getName(): string
	{
		return $this->name;
	}

	/**
	 * Returns a hash where keys are control names and their values
	 * an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()}
	 *
	 * @since  4.0.0
	 *
	 * @return array
	 */
	public function getWidgets(): array
	{
		return [
			'loaded' => [
				'icon' => 'language',
				'widget' => 'PhpDebugBar.Widgets.languageFilesWidget',
				'map' => $this->name,
				'default' => '[]'
			],
			'loaded:badge' => [
				'map'     => $this->name . '.count',
				'default' => 'null',
			],
		];
	}

	/**
	 * Returns an array with the following keys:
	 *  - base_path
	 *  - base_url
	 *  - css: an array of filenames
	 *  - js: an array of filenames
	 *
	 * @since  4.0.0
	 * @return array
	 */
	public function getAssets(): array
	{
		return [
			'js' => Uri::root(true) . '/media/plg_system_debug/widgets/languageFiles/widget.min.js',
			'css' => Uri::root(true) . '/media/plg_system_debug/widgets/languageFiles/widget.min.css',
		];
	}
}

The same content is in 4 releases, Joomla 4.0.0-beta2 to 4.0.0-beta5. See them all, or every version of this file.