[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/MVC/Factory/ -> ApiMVCFactory.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  namespace Joomla\CMS\MVC\Factory;
  11  
  12  // phpcs:disable PSR1.Files.SideEffects
  13  \defined('JPATH_PLATFORM') or die;
  14  // phpcs:enable PSR1.Files.SideEffects
  15  
  16  /**
  17   * Factory to create MVC objects based on a namespace. Note that in an API Application model and table objects will be
  18   * created from their administrator counterparts.
  19   *
  20   * @since  4.0.0
  21   */
  22  final class ApiMVCFactory extends MVCFactory
  23  {
  24      /**
  25       * Method to load and return a model object.
  26       *
  27       * @param   string  $name    The name of the model.
  28       * @param   string  $prefix  Optional model prefix.
  29       * @param   array   $config  Optional configuration array for the model.
  30       *
  31       * @return  \Joomla\CMS\MVC\Model\ModelInterface  The model object
  32       *
  33       * @since   4.0.0
  34       * @throws  \Exception
  35       */
  36      public function createModel($name, $prefix = '', array $config = array())
  37      {
  38          $model = parent::createModel($name, $prefix, $config);
  39  
  40          if (!$model) {
  41              $model = parent::createModel($name, 'Administrator', $config);
  42          }
  43  
  44          return $model;
  45      }
  46  
  47      /**
  48       * Method to load and return a table object.
  49       *
  50       * @param   string  $name    The name of the table.
  51       * @param   string  $prefix  Optional table prefix.
  52       * @param   array   $config  Optional configuration array for the table.
  53       *
  54       * @return  \Joomla\CMS\Table\Table  The table object
  55       *
  56       * @since   4.0.0
  57       * @throws  \Exception
  58       */
  59      public function createTable($name, $prefix = '', array $config = array())
  60      {
  61          $table = parent::createTable($name, $prefix, $config);
  62  
  63          if (!$table) {
  64              $table = parent::createTable($name, 'Administrator', $config);
  65          }
  66  
  67          return $table;
  68      }
  69  }


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