CoreFiles by mySites.guru
UserCollector.php62 lines, 1,404 bytes, from Joomla_4.4.14-Stable-Full_Package.zip
Raw History Compare with 4.4.13
md5
4a44024d15b45fe620e47e2b9c5506e2
sha1
cb8be06cfa9372c0b03f2b2a9729bb86eaadcfbd
sha256
a87d51044356359df5bbacb8bd42c405040199a7f7e8d79d8dd62ae06ba14fe2
<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  System.Debug
 *
 * @copyright   (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\System\Debug\DataCollector;

use DebugBar\DataCollector\DataCollectorInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\User\UserFactoryInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * User collector that stores the user id of the person making the request allowing us to filter on it after storage
 *
 * @since  4.2.4
 */
class UserCollector implements DataCollectorInterface
{
    /**
     * Collector name.
     *
     * @var   string
     * @since 4.2.4
     */
    private $name = 'juser';

    /**
     * Called by the DebugBar when data needs to be collected
     *
     * @since  4.2.4
     *
     * @return array Collected data
     */
    public function collect()
    {
        $user = Factory::getApplication()->getIdentity()
            ?: Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById(0);

        return ['user_id' => $user->id];
    }

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

The same content is in 220 releases, Joomla 4.2.5-rc1 to 6.2.1-rc1. See them all, or every version of this file.