[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Extension/Service/Provider/ -> MVCFactory.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Extension\Service\Provider;
  11  
  12  use Joomla\CMS\Cache\CacheControllerFactoryInterface;
  13  use Joomla\CMS\Form\FormFactoryInterface;
  14  use Joomla\CMS\MVC\Factory\ApiMVCFactory;
  15  use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
  16  use Joomla\CMS\Router\SiteRouter;
  17  use Joomla\Database\DatabaseInterface;
  18  use Joomla\DI\Container;
  19  use Joomla\DI\ServiceProviderInterface;
  20  use Joomla\Event\DispatcherInterface;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('JPATH_PLATFORM') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Service provider for the service MVC factory.
  28   *
  29   * @since  4.0.0
  30   */
  31  class MVCFactory implements ServiceProviderInterface
  32  {
  33      /**
  34       * The extension namespace
  35       *
  36       * @var  string
  37       *
  38       * @since   4.0.0
  39       */
  40      private $namespace;
  41  
  42      /**
  43       * MVCFactory constructor.
  44       *
  45       * @param   string  $namespace  The namespace
  46       *
  47       * @since   4.0.0
  48       */
  49      public function __construct(string $namespace)
  50      {
  51          $this->namespace = $namespace;
  52      }
  53  
  54      /**
  55       * Registers the service provider with a DI container.
  56       *
  57       * @param   Container  $container  The DI container.
  58       *
  59       * @return  void
  60       *
  61       * @since   4.0.0
  62       */
  63      public function register(Container $container)
  64      {
  65          $container->set(
  66              MVCFactoryInterface::class,
  67              function (Container $container) {
  68                  if (\Joomla\CMS\Factory::getApplication()->isClient('api')) {
  69                      $factory = new ApiMVCFactory($this->namespace);
  70                  } else {
  71                      $factory = new \Joomla\CMS\MVC\Factory\MVCFactory($this->namespace);
  72                  }
  73  
  74                  $factory->setFormFactory($container->get(FormFactoryInterface::class));
  75                  $factory->setDispatcher($container->get(DispatcherInterface::class));
  76                  $factory->setDatabase($container->get(DatabaseInterface::class));
  77                  $factory->setSiteRouter($container->get(SiteRouter::class));
  78                  $factory->setCacheControllerFactory($container->get(CacheControllerFactoryInterface::class));
  79  
  80                  return $factory;
  81              }
  82          );
  83      }
  84  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer