当前位置: 首页>>代码示例>>PHP>>正文


PHP Config::getSection方法代码示例

本文整理汇总了PHP中Icinga\Application\Config::getSection方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::getSection方法的具体用法?PHP Config::getSection怎么用?PHP Config::getSection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Icinga\Application\Config的用法示例。


在下文中一共展示了Config::getSection方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getResourceConfig

 /**
  * Get the configuration for a specific resource
  *
  * @param   $resourceName   String      The resource's name
  *
  * @return                  ConfigObject    The configuration of the resource
  *
  * @throws                  ConfigurationError
  */
 public static function getResourceConfig($resourceName)
 {
     self::assertResourcesExist();
     $resourceConfig = self::$resources->getSection($resourceName);
     if ($resourceConfig->isEmpty()) {
         throw new ConfigurationError('Cannot load resource config "%s". Resource does not exist', $resourceName);
     }
     return $resourceConfig;
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:18,代码来源:ResourceFactory.php

示例2: testWhetherConfigSetsSingleSections

 /**
  * @depends testWhetherConfigReturnsSingleSections
  */
 public function testWhetherConfigSetsSingleSections()
 {
     $config = new Config();
     $config->setSection('a', array('b' => 'c'));
     $this->assertInstanceOf('Icinga\\Data\\ConfigObject', $config->getSection('a'), 'Config::setSection does not set a new section');
     $config->setSection('a', array('bb' => 'cc'));
     $this->assertNull($config->getSection('a')->b, 'Config::setSection does not overwrite existing sections');
     $this->assertEquals('cc', $config->getSection('a')->bb, 'Config::setSection does not overwrite existing sections');
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:12,代码来源:ConfigTest.php

示例3: create

 /**
  * Create and return a user backend with the given name and given configuration applied to it
  *
  * @param   string          $name
  * @param   ConfigObject    $backendConfig
  *
  * @return  UserBackendInterface
  *
  * @throws  ConfigurationError
  */
 public static function create($name, ConfigObject $backendConfig = null)
 {
     if ($backendConfig === null) {
         self::assertBackendsExist();
         if (self::$backends->hasSection($name)) {
             $backendConfig = self::$backends->getSection($name);
         } else {
             throw new ConfigurationError('User backend "%s" does not exist', $name);
         }
     }
     if ($backendConfig->name !== null) {
         $name = $backendConfig->name;
     }
     if (!($backendType = strtolower($backendConfig->backend))) {
         throw new ConfigurationError('Authentication configuration for user backend "%s" is missing the \'backend\' directive', $name);
     }
     if ($backendType === 'external') {
         $backend = new ExternalBackend($backendConfig);
         $backend->setName($name);
         return $backend;
     }
     if (in_array($backendType, static::$defaultBackends)) {
         // The default backend check is the first one because of performance reasons:
         // Do not attempt to load a custom user backend unless it's actually required
     } elseif (($customClass = static::getCustomUserBackend($backendType)) !== null) {
         $backend = new $customClass($backendConfig);
         if (!is_a($backend, 'Icinga\\Authentication\\User\\UserBackendInterface')) {
             throw new ConfigurationError('Cannot utilize user backend of type "%s". Class "%s" does not implement UserBackendInterface', $backendType, $customClass);
         }
         $backend->setName($name);
         return $backend;
     } else {
         throw new ConfigurationError('Authentication configuration for user backend "%s" defines an invalid backend type.' . ' Backend type "%s" is not supported', $name, $backendType);
     }
     if ($backendConfig->resource === null) {
         throw new ConfigurationError('Authentication configuration for user backend "%s" is missing the \'resource\' directive', $name);
     }
     $resource = ResourceFactory::create($backendConfig->resource);
     switch ($backendType) {
         case 'db':
             $backend = new DbUserBackend($resource);
             break;
         case 'msldap':
             $backend = new LdapUserBackend($resource);
             $backend->setBaseDn($backendConfig->base_dn);
             $backend->setUserClass($backendConfig->get('user_class', 'user'));
             $backend->setUserNameAttribute($backendConfig->get('user_name_attribute', 'sAMAccountName'));
             $backend->setFilter($backendConfig->filter);
             break;
         case 'ldap':
             $backend = new LdapUserBackend($resource);
             $backend->setBaseDn($backendConfig->base_dn);
             $backend->setUserClass($backendConfig->get('user_class', 'inetOrgPerson'));
             $backend->setUserNameAttribute($backendConfig->get('user_name_attribute', 'uid'));
             $backend->setFilter($backendConfig->filter);
             break;
     }
     $backend->setName($name);
     return $backend;
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:70,代码来源:UserBackend.php

示例4: unshare

 /**
  * Unshare the given navigation item
  *
  * @param   string  $name
  * @param   string  $parent
  *
  * @return  Config              The new config of the given navigation item
  *
  * @throws  NotFoundError       In case no navigation item with the given name is found
  * @throws  IcingaException     In case the navigation item has a parent assigned to it
  */
 public function unshare($name, $parent = null)
 {
     $config = $this->getShareConfig();
     if (!$config->hasSection($name)) {
         throw new NotFoundError('No navigation item called "%s" found', $name);
     }
     $itemConfig = $config->getSection($name);
     if ($parent === null) {
         $parent = $itemConfig->parent;
     }
     if ($parent && $this->hasBeenShared($parent)) {
         throw new IcingaException($this->translate('Unable to unshare navigation item "%s". It is dependent from item "%s".' . ' Dependent items can only be unshared by unsharing their parent'), $name, $parent);
     }
     $children = $this->getFlattenedChildren($name);
     $config->removeSection($name);
     $this->secondaryConfig = $config;
     if (!$itemConfig->owner || $itemConfig->owner === $this->getUser()->getUsername()) {
         $config = $this->getUserConfig();
     } else {
         $config = Config::navigation($itemConfig->type, $itemConfig->owner);
     }
     foreach ($children as $child) {
         $childConfig = $this->secondaryConfig->getSection($child);
         unset($childConfig->owner);
         $this->secondaryConfig->removeSection($child);
         $config->setSection($child, $childConfig);
     }
     unset($itemConfig->owner);
     unset($itemConfig->users);
     unset($itemConfig->groups);
     $config->setSection($name, $itemConfig);
     $this->setIniConfig($config);
     return $config;
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:45,代码来源:NavigationConfigForm.php

示例5: writeConfig

 /**
  * {@inheritdoc}
  */
 protected function writeConfig(Config $config)
 {
     // TODO: Remove this once #11743 is fixed
     $section = $config->getSection('elasticsearch');
     foreach ($section->toArray() as $key => $value) {
         if ($value === null) {
             unset($section->{$key});
         }
     }
     parent::writeConfig($config);
 }
开发者ID:Icinga,项目名称:icingaweb2-module-elasticsearch,代码行数:14,代码来源:ElasticsearchConfigForm.php

示例6: setAuthenticated

 public function setAuthenticated(User $user, $persist = true)
 {
     $username = $user->getUsername();
     try {
         $config = Config::app();
     } catch (NotReadableError $e) {
         Logger::error(new IcingaException('Cannot load preferences for user "%s". An exception was thrown: %s', $username, $e));
         $config = new Config();
     }
     if ($config->get('preferences', 'store', 'ini') !== 'none') {
         $preferencesConfig = $config->getSection('preferences');
         try {
             $preferencesStore = PreferencesStore::create($preferencesConfig, $user);
             $preferences = new Preferences($preferencesStore->load());
         } catch (Exception $e) {
             Logger::error(new IcingaException('Cannot load preferences for user "%s". An exception was thrown: %s', $username, $e));
             $preferences = new Preferences();
         }
     } else {
         $preferences = new Preferences();
     }
     $user->setPreferences($preferences);
     $groups = $user->getGroups();
     foreach (Config::app('groups') as $name => $config) {
         try {
             $groupBackend = UserGroupBackend::create($name, $config);
             $groupsFromBackend = $groupBackend->getMemberships($user);
         } catch (Exception $e) {
             Logger::error('Can\'t get group memberships for user \'%s\' from backend \'%s\'. An exception was thrown: %s', $username, $name, $e);
             continue;
         }
         if (empty($groupsFromBackend)) {
             continue;
         }
         $groupsFromBackend = array_values($groupsFromBackend);
         $groups = array_merge($groups, array_combine($groupsFromBackend, $groupsFromBackend));
     }
     $user->setGroups($groups);
     $admissionLoader = new AdmissionLoader();
     list($permissions, $restrictions) = $admissionLoader->getPermissionsAndRestrictions($user);
     $user->setPermissions($permissions);
     $user->setRestrictions($restrictions);
     $this->user = $user;
     if ($persist) {
         $this->persistCurrentUser();
     }
 }
开发者ID:xert,项目名称:icingaweb2,代码行数:47,代码来源:Manager.php

示例7: setupLogger

 /**
  * Set up logger
  *
  * @return $this
  */
 protected function setupLogger()
 {
     if ($this->config->hasSection('logging')) {
         $loggingConfig = $this->config->getSection('logging');
         try {
             Logger::create($loggingConfig);
         } catch (ConfigurationError $e) {
             Logger::getInstance()->registerConfigError($e->getMessage());
             try {
                 Logger::getInstance()->setLevel($loggingConfig->get('level', Logger::ERROR));
             } catch (ConfigurationError $e) {
                 Logger::getInstance()->registerConfigError($e->getMessage());
             }
         }
     }
     return $this;
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:22,代码来源:ApplicationBootstrap.php

示例8: hasAccessToSharedNavigationItem

 private function hasAccessToSharedNavigationItem(&$config, Config $navConfig)
 {
     // TODO: Provide a more sophisticated solution
     if (isset($config['owner']) && strtolower($config['owner']) === strtolower($this->user->getUsername())) {
         unset($config['owner']);
         unset($config['users']);
         unset($config['groups']);
         return true;
     }
     if (isset($config['parent']) && $navConfig->hasSection($config['parent'])) {
         unset($config['owner']);
         if (isset($this->accessibleMenuItems[$config['parent']])) {
             return $this->accessibleMenuItems[$config['parent']];
         }
         $parentConfig = $navConfig->getSection($config['parent']);
         $this->accessibleMenuItems[$config['parent']] = $this->hasAccessToSharedNavigationItem($parentConfig, $navConfig);
         return $this->accessibleMenuItems[$config['parent']];
     }
     if (isset($config['users'])) {
         $users = array_map('trim', explode(',', strtolower($config['users'])));
         if (in_array('*', $users, true) || in_array(strtolower($this->user->getUsername()), $users, true)) {
             unset($config['owner']);
             unset($config['users']);
             unset($config['groups']);
             return true;
         }
     }
     if (isset($config['groups'])) {
         $groups = array_map('trim', explode(',', strtolower($config['groups'])));
         if (in_array('*', $groups, true)) {
             unset($config['owner']);
             unset($config['users']);
             unset($config['groups']);
             return true;
         }
         $userGroups = array_map('strtolower', $this->user->getGroups());
         $matches = array_intersect($userGroups, $groups);
         if (!empty($matches)) {
             unset($config['owner']);
             unset($config['users']);
             unset($config['groups']);
             return true;
         }
     }
     return false;
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:46,代码来源:Web.php

示例9: diffPropertyDeletions

 /**
  * Search for deleted properties and use the editor to delete these entries
  *
  * @param Config    $oldconfig  The config representing the state before the change
  * @param Config    $newconfig  The config representing the state after the change
  * @param Document  $doc
  *
  * @throws ProgrammingError
  */
 protected function diffPropertyDeletions(Config $oldconfig, Config $newconfig, Document $doc)
 {
     // Iterate over all properties in the old configuration file and remove those that don't
     // exist in the new config
     foreach ($oldconfig->toArray() as $section => $directives) {
         if (!is_array($directives)) {
             Logger::warning('Section-less property ' . (string) $directives . ' was ignored.');
             continue;
         }
         if ($newconfig->hasSection($section)) {
             $newSection = $newconfig->getSection($section);
             $oldDomSection = $doc->getSection($section);
             foreach ($directives as $key => $value) {
                 if ($value instanceof ConfigObject) {
                     throw new ProgrammingError('Cannot diff recursive configs');
                 }
                 if (null === $newSection->get($key) && $oldDomSection->hasDirective($key)) {
                     $oldDomSection->removeDirective($key);
                 }
             }
         } else {
             $doc->removeSection($section);
         }
     }
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:34,代码来源:IniWriter.php


注:本文中的Icinga\Application\Config::getSection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。