[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Menu/ -> MenuFactory.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2017 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\Menu;
  11  
  12  use Joomla\CMS\Cache\CacheControllerFactoryAwareInterface;
  13  use Joomla\CMS\Cache\CacheControllerFactoryAwareTrait;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\Database\DatabaseAwareTrait;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('_JEXEC') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * Default factory for creating Menu objects
  23   *
  24   * @since  4.0.0
  25   */
  26  class MenuFactory implements MenuFactoryInterface
  27  {
  28      use CacheControllerFactoryAwareTrait;
  29      use DatabaseAwareTrait;
  30  
  31      /**
  32       * Creates a new Menu object for the requested format.
  33       *
  34       * @param   string  $client   The name of the client
  35       * @param   array   $options  An associative array of options
  36       *
  37       * @return  AbstractMenu
  38       *
  39       * @since   4.0.0
  40       * @throws  \InvalidArgumentException
  41       */
  42      public function createMenu(string $client, array $options = []): AbstractMenu
  43      {
  44          // Create a Menu object
  45          $classname = __NAMESPACE__ . '\\' . ucfirst(strtolower($client)) . 'Menu';
  46  
  47          if (!class_exists($classname)) {
  48              throw new \InvalidArgumentException(Text::sprintf('JLIB_APPLICATION_ERROR_MENU_LOAD', $client), 500);
  49          }
  50  
  51          if (!array_key_exists('db', $options)) {
  52              $options['db'] = $this->getDatabase();
  53          }
  54  
  55          $instance = new $classname($options);
  56  
  57          if ($instance instanceof CacheControllerFactoryAwareInterface) {
  58              $instance->setCacheControllerFactory($this->getCacheControllerFactory());
  59          }
  60  
  61          return $instance;
  62      }
  63  }


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