ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSettingsFactory.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 2019 Richard Klees, ILIAS Open Source e.V. |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
33 {
37  protected $db;
38 
39  public function __construct(\ilDBInterface $db)
40  {
41  $this->db = $db;
42  }
43 
47  public function settingsFor(string $a_module = "common")
48  {
49  $tmp_dic = $GLOBALS["DIC"] ?? null;
50  try {
51  // ilSetting pulls the database once in the constructor, we force it to
52  // use ours.
54  $DIC["ilDB"] = $this->db;
55  $DIC["ilBench"] = null;
56  $GLOBALS["DIC"] = $DIC;
57 
58  // Always load from db, as caching could be implemented as a
59  // decorator to this.
60  $settings = new ilSetting($a_module, true);
61 
62  // Provoke a setting to populate the value_type in ilSettings,
63  // use a field that is likely to exist.
64  $settings->set(
65  "common",
66  "system_user_id",
67  $settings->get("common", "system_user_id")
68  );
69  } finally {
70  $GLOBALS["DIC"] = $tmp_dic;
71  }
72 
73  return $settings;
74  }
75 }
__construct(\ilDBInterface $db)
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
settingsFor(string $a_module="common")
Get currernt module.
A factory that builds ilSettings that can be used for DI.