[icinga-checkins] icinga.org: icingaweb2/feature/announce-banner-11198: IniRepository: Introduce method createConfig

git at icinga.org git at icinga.org
Fri Nov 4 10:50:04 CET 2016


Module: icingaweb2
Branch: feature/announce-banner-11198
Commit: c44e164de92052f5cd56bec697e993522d83359d
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=c44e164de92052f5cd56bec697e993522d83359d

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Fri Nov  4 10:16:45 2016 +0100

IniRepository: Introduce method createConfig

refs #13034

---

 library/Icinga/Repository/IniRepository.php |   28 +++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/library/Icinga/Repository/IniRepository.php b/library/Icinga/Repository/IniRepository.php
index 74fe721..2005130 100644
--- a/library/Icinga/Repository/IniRepository.php
+++ b/library/Icinga/Repository/IniRepository.php
@@ -378,6 +378,34 @@ abstract class IniRepository extends Repository implements Extensible, Updatable
     }
 
     /**
+     * Create and return a Config for the given meta and table
+     *
+     * @param   array   $meta
+     * @param   string  $table
+     *
+     * @return  Config
+     *
+     * @throws  ProgrammingError    In case the given meta is invalid
+     */
+    protected function createConfig(array $meta, $table)
+    {
+        if (! isset($meta['name'])) {
+            throw new ProgrammingError('Config file name missing for table "%s"', $table);
+        } elseif (! isset($meta['keyColumn'])) {
+            throw new ProgrammingError('Config key column name missing for table "%s"', $table);
+        }
+
+        if (isset($meta['module'])) {
+            $config = Config::module($meta['module'], $meta['name']);
+        } else {
+            $config = Config::app($meta['name']);
+        }
+
+        $config->getConfigObject()->setKeyColumn($meta['keyColumn']);
+        return $config;
+    }
+
+    /**
      * Extract and return the section name off of the given $config
      *
      * @param   array|ConfigObject  $config



More information about the icinga-checkins mailing list