[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/application/src/Controller/ -> ContainerControllerResolver.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework Application Package
   4   *
   5   * @copyright  Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\Application\Controller;
  10  
  11  use Psr\Container\ContainerInterface;
  12  
  13  /**
  14   * Controller resolver which supports creating controllers from a PSR-11 compatible container
  15   *
  16   * Controllers must be registered in the container using their FQCN as a service key
  17   *
  18   * @since  2.0.0
  19   */
  20  class ContainerControllerResolver extends ControllerResolver
  21  {
  22      /**
  23       * The container to search for controllers in
  24       *
  25       * @var    ContainerInterface
  26       * @since  2.0.0
  27       */
  28      private $container;
  29  
  30      /**
  31       * Constructor
  32       *
  33       * @param   ContainerInterface  $container  The container to search for controllers in
  34       *
  35       * @since   2.0.0
  36       */
  37  	public function __construct(ContainerInterface $container)
  38      {
  39          $this->container = $container;
  40      }
  41  
  42      /**
  43       * Instantiate a controller class
  44       *
  45       * @param   string  $class  The class to instantiate
  46       *
  47       * @return  object  Controller class instance
  48       *
  49       * @since   2.0.0
  50       */
  51  	protected function instantiateController(string $class): object
  52      {
  53          if ($this->container->has($class))
  54          {
  55              return $this->container->get($class);
  56          }
  57  
  58          return parent::instantiateController($class);
  59      }
  60  }


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