[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Service/Provider/ -> Config.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\Service\Provider;
  11  
  12  use Joomla\DI\Container;
  13  use Joomla\DI\ServiceProviderInterface;
  14  use Joomla\Registry\Registry;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('JPATH_PLATFORM') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Service provider for the application's config dependency
  22   *
  23   * @since  4.0.0
  24   */
  25  class Config implements ServiceProviderInterface
  26  {
  27      /**
  28       * Registers the service provider with a DI container.
  29       *
  30       * @param   Container  $container  The DI container.
  31       *
  32       * @return  void
  33       *
  34       * @since   4.0.0
  35       */
  36      public function register(Container $container)
  37      {
  38          $container->alias('config', 'JConfig')
  39              ->share(
  40                  'JConfig',
  41                  function (Container $container) {
  42                      if (!is_file(JPATH_CONFIGURATION . '/configuration.php')) {
  43                          return new Registry();
  44                      }
  45  
  46                      \JLoader::register('JConfig', JPATH_CONFIGURATION . '/configuration.php');
  47  
  48                      if (!class_exists('JConfig')) {
  49                          throw new \RuntimeException('Configuration class does not exist.');
  50                      }
  51  
  52                      return new Registry(new \JConfig());
  53                  },
  54                  true
  55              );
  56      }
  57  }


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