CoreFiles by mySites.guru
UserCollector.php62 lines, 1,404 bytes, from Joomla_4.2.4-Stable-Full_Package.zip
Raw History Compare with 4.2.3
md5
1ffb4a3e4710034fcf5b934d1c71977f
sha1
f55d14852cfb219225837c951edbe207647ca4d8
sha256
254bbe192848ff2d1f2828fae481c11e6b659acc2d1f1348bd6f464365fee1d9
<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  System.Debug
 *
 * @copyright   (C) 2018 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;
    }
}

No other release has this exact content. See every version of this file.