CoreFiles by mySites.guru
HelperFactory.php75 lines, 1,620 bytes, from Joomla_5.2.5-Stable-Full_Package.zip
Raw History Compare with 5.2.4
md5
476dc921c726c2959fead2c3ce8fb988
sha1
3ae768684524b828b58ef1ae4605f1ecadf20434
sha256
ab56e2135aa3228dafc9812d097894c848e780b61359aed4e4ee8f2d275a50c0
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Helper;

use Joomla\Database\DatabaseAwareInterface;
use Joomla\Database\DatabaseAwareTrait;

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

/**
 * Namespace based implementation of the HelperFactoryInterface
 *
 * @since  4.0.0
 */
class HelperFactory implements HelperFactoryInterface
{
    use DatabaseAwareTrait;

    /**
     * The extension namespace
     *
     * @var  string
     *
     * @since   4.0.0
     */
    private $namespace;

    /**
     * HelperFactory constructor.
     *
     * @param   string  $namespace  The namespace
     *
     * @since   4.0.0
     */
    public function __construct(string $namespace)
    {
        $this->namespace = $namespace;
    }

    /**
     * Returns a helper instance for the given name.
     *
     * @param   string  $name    The name
     * @param   array   $config  The config
     *
     * @return  \stdClass
     *
     * @since   4.0.0
     */
    public function getHelper(string $name, array $config = [])
    {
        $className = '\\' . trim($this->namespace, '\\') . '\\' . $name;

        if (!class_exists($className)) {
            return null;
        }

        $helper = new $className($config);

        if ($helper instanceof DatabaseAwareInterface) {
            $helper->setDatabase($this->getDatabase());
        }

        return $helper;
    }
}

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