[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/di/src/ -> ContainerAwareTrait.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework DI Package
   4   *
   5   * @copyright  Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\DI;
  10  
  11  use Joomla\DI\Exception\ContainerNotFoundException;
  12  
  13  /**
  14   * Defines the trait for a Container Aware Class.
  15   *
  16   * @since  1.2
  17   */
  18  trait ContainerAwareTrait
  19  {
  20      /**
  21       * DI Container
  22       *
  23       * @var    Container
  24       * @since  1.2
  25       */
  26      private $container;
  27  
  28      /**
  29       * Get the DI container.
  30       *
  31       * @return  Container
  32       *
  33       * @since   1.2
  34       * @throws  ContainerNotFoundException May be thrown if the container has not been set.
  35       */
  36  	protected function getContainer()
  37      {
  38          if ($this->container)
  39          {
  40              return $this->container;
  41          }
  42  
  43          throw new ContainerNotFoundException('Container not set in ' . \get_class($this));
  44      }
  45  
  46      /**
  47       * Set the DI container.
  48       *
  49       * @param   Container  $container  The DI container.
  50       *
  51       * @return  $this
  52       *
  53       * @since   1.2
  54       */
  55  	public function setContainer(Container $container)
  56      {
  57          $this->container = $container;
  58  
  59          return $this;
  60      }
  61  }


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