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


PHP Application\Config类代码示例

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


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

示例1: fromConfig

 /**
  * Create a transport from config
  *
  * @param   ConfigObject  $config
  *
  * @return  LocalCommandFile|RemoteCommandFile
  * @throws  ConfigurationError
  */
 public static function fromConfig(ConfigObject $config)
 {
     $config = clone $config;
     switch (strtolower($config->transport)) {
         case RemoteCommandFile::TRANSPORT:
             $transport = new RemoteCommandFile();
             break;
         case LocalCommandFile::TRANSPORT:
         case '':
             // Casting null to string is the empty string
             $transport = new LocalCommandFile();
             break;
         default:
             throw new ConfigurationError('Can\'t create command transport \'%s\'. Invalid transport defined in \'%s\'.' . ' Use one of \'%s\' or \'%s\'.', $config->transport, self::$config->getConfigFile(), LocalCommandFile::TRANSPORT, RemoteCommandFile::TRANSPORT);
     }
     unset($config->transport);
     foreach ($config as $key => $value) {
         $method = 'set' . ucfirst($key);
         if (!method_exists($transport, $method)) {
             // Ignore settings from config that don't have a setter on the transport instead of throwing an
             // exception here because the transport should throw an exception if it's not fully set up
             // when being about to send a command
             continue;
         }
         $transport->{$method}($value);
     }
     return $transport;
 }
开发者ID:NerdGZ,项目名称:icingaweb2,代码行数:36,代码来源:CommandTransport.php

示例2: createBackendConfiguration

 /**
  * Return the user backend configuration as Config object
  *
  * @return  Config
  */
 protected function createBackendConfiguration()
 {
     $config = new Config();
     $backendConfig = $this->backendConfig;
     $backendConfig['resource'] = $this->resourceConfig['name'];
     $config->setSection($this->backendConfig['name'], $backendConfig);
     return $config;
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:13,代码来源:UserGroupBackendPage.php

示例3: setResourceConfig

 /**
  * Set the resource configuration to use
  *
  * @param   array   $config
  *
  * @return  $this
  */
 public function setResourceConfig(array $config)
 {
     $resourceConfig = new Config();
     $resourceConfig->setSection($config['name'], $config);
     ResourceFactory::setConfig($resourceConfig);
     $this->config = $config;
     return $this;
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:15,代码来源:AuthBackendPage.php

示例4: save

 /**
  * Persist the current configuration to disk
  *
  * If an error occurs the user is shown a view describing the issue and displaying the raw INI configuration.
  *
  * @return  bool                    Whether the configuration could be persisted
  */
 public function save()
 {
     try {
         $this->config->saveIni();
     } catch (Exception $e) {
         $this->addDecorator('ViewScript', array('viewModule' => 'default', 'viewScript' => 'showConfiguration.phtml', 'errorMessage' => $e->getMessage(), 'configString' => $this->config, 'filePath' => $this->config->getConfigFile(), 'placement' => Zend_Form_Decorator_Abstract::PREPEND));
         return false;
     }
     return true;
 }
开发者ID:JakobGM,项目名称:icingaweb2,代码行数:17,代码来源:ConfigForm.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: createElements

 /**
  * (non-PHPDoc)
  * @see \Icinga\Web\Form::createElements() For the method documentation.
  */
 public function createElements(array $formData = array())
 {
     $config = Config::module('monitoring');
     parent::createElements($formData);
     $this->addElements(array(array('checkbox', 'all_services', array('label' => $this->translate('All Services'), 'value' => (bool) $config->get('settings', 'hostcheck_all_services', false), 'description' => $this->translate('Schedule check for all services on the hosts and the hosts themselves.')))));
     return $this;
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:11,代码来源:ScheduleHostCheckCommandForm.php

示例7: init

 protected function init()
 {
     $cfg = Config::module('pnp4nagios')->getSection('pnp4nagios');
     $this->configDir = rtrim($cfg->get('config_dir', $this->configDir), '/');
     $this->baseUrl = rtrim($cfg->get('base_url', $this->baseUrl), '/');
     $this->readPnpConfig();
 }
开发者ID:0svald,项目名称:icingaweb2-module-pnp,代码行数:7,代码来源:Grapher.php

示例8: 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

示例9: 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

示例10: setAuthenticated

 public function setAuthenticated(User $user, $persist = true)
 {
     $username = $user->getUsername();
     try {
         $config = IcingaConfig::app();
     } catch (NotReadableError $e) {
         Logger::error(new Exception('Cannot load preferences for user "' . $username . '". An exception was thrown', 0, $e));
         $config = new Zend_Config(array());
     }
     if (($preferencesConfig = $config->preferences) !== null) {
         try {
             $preferencesStore = PreferencesStore::create($preferencesConfig, $user);
             $preferences = new Preferences($preferencesStore->load());
         } catch (NotReadableError $e) {
             Logger::error(new Exception('Cannot load preferences for user "' . $username . '". An exception was thrown', 0, $e));
             $preferences = new Preferences();
         }
     } else {
         $preferences = new Preferences();
     }
     $user->setPreferences($preferences);
     $membership = new Membership();
     $groups = $membership->getGroupsByUsername($username);
     $user->setGroups($groups);
     $admissionLoader = new AdmissionLoader();
     $user->setPermissions($admissionLoader->getPermissions($username, $groups));
     $user->setRestrictions($admissionLoader->getRestrictions($username, $groups));
     $this->user = $user;
     if ($persist == true) {
         $session = Session::getSession();
         $session->refreshId();
         $this->persistCurrentUser();
     }
 }
开发者ID:vbereza,项目名称:icinga2-migration,代码行数:34,代码来源:Manager.php

示例11: writeConfig

 /**
  * {@inheritDoc}
  */
 protected function writeConfig(Config $config)
 {
     parent::writeConfig($config);
     if ($this->updatedAppConfig !== null) {
         $this->updatedAppConfig->saveIni();
     }
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:10,代码来源:ResourceConfigForm.php

示例12: applyRoles

 /**
  * Apply permissions, restrictions and roles to the given user
  *
  * @param   User    $user
  */
 public function applyRoles(User $user)
 {
     $username = $user->getUsername();
     try {
         $roles = Config::app('roles');
     } catch (NotReadableError $e) {
         Logger::error('Can\'t get permissions and restrictions for user \'%s\'. An exception was thrown:', $username, $e);
         return;
     }
     $userGroups = $user->getGroups();
     $permissions = array();
     $restrictions = array();
     $roleObjs = array();
     foreach ($roles as $roleName => $role) {
         if ($this->match($username, $userGroups, $role)) {
             $permissionsFromRole = StringHelper::trimSplit($role->permissions);
             $permissions = array_merge($permissions, array_diff($permissionsFromRole, $permissions));
             $restrictionsFromRole = $role->toArray();
             unset($restrictionsFromRole['users']);
             unset($restrictionsFromRole['groups']);
             unset($restrictionsFromRole['permissions']);
             foreach ($restrictionsFromRole as $name => $restriction) {
                 if (!isset($restrictions[$name])) {
                     $restrictions[$name] = array();
                 }
                 $restrictions[$name][] = $restriction;
             }
             $roleObj = new Role();
             $roleObjs[] = $roleObj->setName($roleName)->setPermissions($permissionsFromRole)->setRestrictions($restrictionsFromRole);
         }
     }
     $user->setPermissions($permissions);
     $user->setRestrictions($restrictions);
     $user->setRoles($roleObjs);
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:40,代码来源:AdmissionLoader.php

示例13: fromConfig

 /**
  * Create menu from the application's menu config file plus the config files from all enabled modules
  *
  * @return  self
  */
 public static function fromConfig()
 {
     $menu = new static('menu');
     $manager = Icinga::app()->getModuleManager();
     try {
         $menuConfigs = array(Config::app('menu'));
     } catch (NotReadableError $e) {
         Logger::error($e);
         $menuConfigs = array();
     }
     try {
         $modules = $manager->listEnabledModules();
     } catch (NotReadableError $e) {
         Logger::error($e);
         $modules = array();
     }
     foreach ($modules as $moduleName) {
         try {
             $moduleMenuConfig = Config::module($moduleName, 'menu');
         } catch (NotReadableError $e) {
             Logger::error($e);
             $moduleMenuConfig = array();
         }
         if (!empty($moduleMenuConfig)) {
             $menuConfigs[] = $moduleMenuConfig;
         }
     }
     return $menu->loadMenuItems($menu->flattenConfigs($menuConfigs));
 }
开发者ID:vbereza,项目名称:icinga2-migration,代码行数:34,代码来源:Menu.php

示例14: valid

 /**
  * Check whether the current user backend is valid, i.e. it's enabled, not an external user backend and whether its
  * config is valid
  *
  * @return bool
  */
 public function valid()
 {
     if (!$this->config->valid()) {
         // Stop when there are no more backends to check
         return false;
     }
     $backendConfig = $this->config->current();
     if ((bool) $backendConfig->get('disabled', false)) {
         $this->next();
         return $this->valid();
     }
     $name = $this->key();
     try {
         $backend = UserBackend::create($name, $backendConfig);
     } catch (ConfigurationError $e) {
         Logger::error(new ConfigurationError('Can\'t create authentication backend "%s". An exception was thrown:', $name, $e));
         $this->next();
         return $this->valid();
     }
     if ($this->getSkipExternalBackends() && $backend instanceof ExternalBackend) {
         $this->next();
         return $this->valid();
     }
     $this->currentBackend = $backend;
     return true;
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:32,代码来源:AuthChain.php

示例15: indexAction

 /**
  * My account
  */
 public function indexAction()
 {
     $config = Config::app()->getSection('global');
     $user = $this->Auth()->getUser();
     if ($user->getAdditional('backend_type') === 'db') {
         try {
             $userBackend = UserBackend::create($user->getAdditional('backend_name'));
         } catch (ConfigurationError $e) {
             $userBackend = null;
         }
         if ($userBackend !== null) {
             $changePasswordForm = new ChangePasswordForm();
             $changePasswordForm->setBackend($userBackend)->handleRequest();
             $this->view->changePasswordForm = $changePasswordForm;
         }
     }
     $form = new PreferenceForm();
     $form->setPreferences($user->getPreferences());
     if ($config->get('config_backend', 'ini') !== 'none') {
         $form->setStore(PreferencesStore::create(new ConfigObject(array('store' => $config->get('config_backend', 'ini'), 'resource' => $config->config_resource)), $user));
     }
     $form->handleRequest();
     $this->view->form = $form;
     $this->getTabs()->activate('account');
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:28,代码来源:AccountController.php


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