- md5
- 77e1ad404cb33fd2469422549d4be6ec
- sha1
- 4381e7a467c6bfb02b8afc4b8cbf0c13893afe66
- sha256
- 55f85f9156b34ee00ea8f3af0eac04eb58f8ca315bd9f1eaf658f4c43c46f42f
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
<?php
/**
* Joomla! Content Management System
*
* @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\CMS\Extension\Service\Provider;
use Joomla\CMS\Cache\CacheControllerFactoryAwareInterface;
use Joomla\CMS\Cache\CacheControllerFactoryInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormFactoryAwareInterface;
use Joomla\CMS\Form\FormFactoryInterface;
use Joomla\CMS\Mail\MailerFactoryAwareInterface;
use Joomla\CMS\Mail\MailerFactoryInterface;
use Joomla\CMS\MVC\Factory\ApiMVCFactory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Router\SiteRouter;
use Joomla\CMS\Router\SiteRouterAwareInterface;
use Joomla\CMS\User\UserFactoryAwareInterface;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Database\DatabaseAwareInterface;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherAwareInterface;
use Joomla\Event\DispatcherInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Service provider for the service MVC factory.
*
* @since 4.0.0
*/
class MVCFactory implements ServiceProviderInterface
{
/**
* The extension namespace
*
* @var string
*
* @since 4.0.0
*/
private $namespace;
/**
* MVCFactory constructor.
*
* @param string $namespace The namespace
*
* @since 4.0.0
*/
public function __construct(string $namespace)
{
$this->namespace = $namespace;
}
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0.0
*/
public function register(Container $container)
{
$container->set(
MVCFactoryInterface::class,
function (Container $container) {
$factory = $this->createMVCFactory();
$this->injectServicesIntoFactory($factory, $container);
return $factory;
}
);
}
/**
* Return component namespace
*
* @return string
*
* @since 6.2.0
*/
protected function getNamespace(): string
{
return $this->namespace;
}
/**
* Create MVC Factory
*
* @return MVCFactoryInterface
*
* @since 6.2.0
*/
protected function createMVCFactory(): MVCFactoryInterface
{
if (Factory::getApplication()->isClient('api')) {
return new ApiMVCFactory($this->namespace);
}
return new \Joomla\CMS\MVC\Factory\MVCFactory($this->namespace);
}
/**
* Inject services from container into MVC Factory
*
* @param MVCFactoryInterface $factory The MVC Factory
* @param Container $container The DI container
*
* @return void
*
* @since 6.2.0
*/
protected function injectServicesIntoFactory(MVCFactoryInterface $factory, Container $container): void
{
if ($factory instanceof FormFactoryAwareInterface) {
$factory->setFormFactory($container->get(FormFactoryInterface::class));
}
if ($factory instanceof DispatcherAwareInterface) {
$factory->setDispatcher($container->get(DispatcherInterface::class));
}
if ($factory instanceof DatabaseAwareInterface) {
$factory->setDatabase($container->get(DatabaseInterface::class));
}
if ($factory instanceof SiteRouterAwareInterface) {
$factory->setSiteRouter($container->get(SiteRouter::class));
}
if ($factory instanceof CacheControllerFactoryAwareInterface) {
$factory->setCacheControllerFactory($container->get(CacheControllerFactoryInterface::class));
}
if ($factory instanceof UserFactoryAwareInterface) {
$factory->setUserFactory($container->get(UserFactoryInterface::class));
}
if ($factory instanceof MailerFactoryAwareInterface) {
$factory->setMailerFactory($container->get(MailerFactoryInterface::class));
}
}
}
No other release has this exact content. See every version of this file.