Example #1
0
 public function testWhetherNestedPropertiesAreInserted()
 {
     $target = $this->writeConfigToTemporaryFile('');
     $config = Config::fromArray(array('a' => array('b' => 'c')));
     $writer = new IniWriter($config, $target);
     $writer->write();
     $newConfig = Config::fromIni($target);
     $this->assertInstanceOf('Icinga\\Data\\ConfigObject', $newConfig->getSection('a'), 'IniWriter does not insert nested properties');
     $this->assertEquals('c', $newConfig->getSection('a')->get('b'), 'IniWriter does not insert nested properties');
 }
Example #2
0
 /**
  * Render the Zend_Config into a config filestring
  *
  * @return  string
  */
 public function render()
 {
     if (file_exists($this->filename)) {
         $oldconfig = Config::fromIni($this->filename);
         $content = trim(file_get_contents($this->filename));
     } else {
         $oldconfig = Config::fromArray(array());
         $content = '';
     }
     $doc = IniParser::parseIni($content);
     $this->diffPropertyUpdates($this->config, $doc);
     $this->diffPropertyDeletions($oldconfig, $this->config, $doc);
     $doc = $this->updateSectionOrder($this->config, $doc);
     return $doc->render();
 }
Example #3
0
 /**
  * Create and return a resource based on the given configuration
  *
  * @param   ConfigObject    $config     The configuration of the resource to create
  *
  * @return  Selectable                  The resource
  * @throws  ConfigurationError          In case of an unsupported type or invalid configuration
  */
 public static function createResource(ConfigObject $config)
 {
     switch (strtolower($config->type)) {
         case 'db':
             $resource = new DbConnection($config);
             break;
         case 'ldap':
             if (empty($config->root_dn)) {
                 throw new ConfigurationError('LDAP root DN missing');
             }
             $resource = new LdapConnection($config);
             break;
         case 'livestatus':
             $resource = new LivestatusConnection($config->socket);
             break;
         case 'file':
             $resource = new FileReader($config);
             break;
         case 'ini':
             $resource = Config::fromIni($config->ini);
             break;
         default:
             throw new ConfigurationError('Unsupported resource type "%s"', $config->type);
     }
     return $resource;
 }
Example #4
0
 /**
  * @return bool
  */
 private function loadUserDashboards()
 {
     try {
         $config = Config::fromIni($this->getConfigFile());
     } catch (NotReadableError $e) {
         return;
     }
     if (!count($config)) {
         return false;
     }
     $panes = array();
     $dashlets = array();
     foreach ($config as $key => $part) {
         if (strpos($key, '.') === false) {
             if ($this->hasPane($part->title)) {
                 $panes[$key] = $this->getPane($part->title);
             } else {
                 $panes[$key] = new Pane($key);
                 $panes[$key]->setTitle($part->title);
             }
             $panes[$key]->setUserWidget();
             if ((bool) $part->get('disabled', false) === true) {
                 $panes[$key]->setDisabled();
             }
         } else {
             list($paneName, $dashletName) = explode('.', $key, 2);
             $part->pane = $paneName;
             $part->dashlet = $dashletName;
             $dashlets[] = $part;
         }
     }
     foreach ($dashlets as $dashletData) {
         $pane = null;
         if (array_key_exists($dashletData->pane, $panes) === true) {
             $pane = $panes[$dashletData->pane];
         } elseif (array_key_exists($dashletData->pane, $this->panes) === true) {
             $pane = $this->panes[$dashletData->pane];
         } else {
             continue;
         }
         $dashlet = new DashboardDashlet($dashletData->title, $dashletData->url, $pane);
         if ((bool) $dashletData->get('disabled', false) === true) {
             $dashlet->setDisabled(true);
         }
         $dashlet->setUserWidget();
         $pane->addDashlet($dashlet);
     }
     $this->mergePanes($panes);
     return true;
 }
Example #5
0
 /**
  * Load and return this user's navigation configuration
  *
  * @return  Config
  */
 public function loadNavigationConfig()
 {
     return Config::fromIni(Config::resolvePath('preferences') . DIRECTORY_SEPARATOR . $this->getUsername() . DIRECTORY_SEPARATOR . 'navigation.ini');
 }
Example #6
0
 /**
  * @expectedException Icinga\Exception\NotReadableError
  */
 public function testWhetherFromIniThrowsAnExceptionOnInsufficientPermission()
 {
     Config::fromIni('/etc/shadow');
 }
Example #7
0
    /**
     * @depends testWhetherNestedPropertiesOfExtendingSectionsAreInserted
     */
    public function testWhetherNestedPropertiesOfExtendingSectionsAreDeleted()
    {
        $this->markTestSkipped('Implementation has changed. There is no "Extend" functionality anymore in our Config object');
        $target = $this->writeConfigToTemporaryFile(<<<'EOD'
[foo]
a.b = "c"

[bar : foo]
d.e = "f"
EOD
);
        $config = Config::fromArray(array('foo' => array('a' => array('b' => 'c')), 'bar' => array()));
        $config->setExtend('bar', 'foo');
        $writer = new IniWriter(array('config' => $config, 'filename' => $target));
        $writer->write();
        $newConfig = Config::fromIni($target);
        $this->assertNull($newConfig->get('bar')->get('d'), 'IniWriter does not delete nested properties of extending sections');
    }