Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Container class.
  19   *
  20   * @package    mod_forum
  21   * @copyright  2018 Ryan Wyllie <ryan@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace mod_forum\local;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use mod_forum\local\factories\renderer as renderer_factory;
  30  use mod_forum\local\factories\legacy_data_mapper as legacy_data_mapper_factory;
  31  use mod_forum\local\factories\entity as entity_factory;
  32  use mod_forum\local\factories\exporter as exporter_factory;
  33  use mod_forum\local\factories\manager as manager_factory;
  34  use mod_forum\local\factories\vault as vault_factory;
  35  use mod_forum\local\factories\builder as builder_factory;
  36  use mod_forum\local\factories\url as url_factory;
  37  
  38  /**
  39   * Container class.
  40   *
  41   * This class provides helper methods with static configurations to get any
  42   * of the factories from the "local" namespace.
  43   *
  44   * @copyright  2018 Ryan Wyllie <ryan@moodle.com>
  45   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  46   */
  47  class container {
  48      /**
  49       * Create the renderer factory.
  50       *
  51       * @return renderer_factory
  52       */
  53      public static function get_renderer_factory() : renderer_factory {
  54          global $PAGE;
  55  
  56          return new renderer_factory(
  57              self::get_legacy_data_mapper_factory(),
  58              self::get_exporter_factory(),
  59              self::get_vault_factory(),
  60              self::get_manager_factory(),
  61              self::get_entity_factory(),
  62              self::get_builder_factory(),
  63              self::get_url_factory(),
  64              $PAGE
  65          );
  66      }
  67  
  68      /**
  69       * Create the legacy data mapper factory.
  70       *
  71       * @return legacy_data_mapper_factory
  72       */
  73      public static function get_legacy_data_mapper_factory() : legacy_data_mapper_factory {
  74          return new legacy_data_mapper_factory();
  75      }
  76  
  77      /**
  78       * Create the exporter factory.
  79       *
  80       * @return exporter_factory
  81       */
  82      public static function get_exporter_factory() : exporter_factory {
  83          return new exporter_factory(
  84              self::get_legacy_data_mapper_factory(),
  85              self::get_manager_factory(),
  86              self::get_url_factory(),
  87              self::get_vault_factory()
  88          );
  89      }
  90  
  91      /**
  92       * Create the vault factory.
  93       *
  94       * @return vault_factory
  95       */
  96      public static function get_vault_factory() : vault_factory {
  97          global $DB;
  98  
  99          return new vault_factory(
 100              $DB,
 101              self::get_entity_factory(),
 102              get_file_storage(),
 103              self::get_legacy_data_mapper_factory()
 104          );
 105      }
 106  
 107      /**
 108       * Create the manager factory.
 109       *
 110       * @return manager_factory
 111       */
 112      public static function get_manager_factory() : manager_factory {
 113          return new manager_factory(
 114              self::get_legacy_data_mapper_factory()
 115          );
 116      }
 117  
 118      /**
 119       * Create the entity factory.
 120       *
 121       * @return entity_factory
 122       */
 123      public static function get_entity_factory() : entity_factory {
 124          return new entity_factory();
 125      }
 126  
 127      /**
 128       * Create the builder factory.
 129       *
 130       * @return builder_factory
 131       */
 132      public static function get_builder_factory() : builder_factory {
 133          global $PAGE;
 134  
 135          return new builder_factory(
 136              self::get_legacy_data_mapper_factory(),
 137              self::get_exporter_factory(),
 138              self::get_vault_factory(),
 139              self::get_manager_factory(),
 140              $PAGE->get_renderer('mod_forum')
 141          );
 142      }
 143  
 144      /**
 145       * Create the URL factory.
 146       *
 147       * @return url_factory
 148       */
 149      public static function get_url_factory() : url_factory {
 150          return new url_factory(
 151              self::get_legacy_data_mapper_factory()
 152          );
 153      }
 154  }