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


PHP Config::app方法代码示例

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


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

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

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

示例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) {
         $authConfig = Config::app('authentication');
         if ($authConfig->hasSection($name)) {
             $backendConfig = $authConfig->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:scibi,项目名称:icingaweb2,代码行数:70,代码来源:UserBackend.php

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

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

示例6: applicationlogAction

 /**
  * Display the application log
  */
 public function applicationlogAction()
 {
     if (!Logger::writesToFile()) {
         $this->httpNotFound('Page not found');
     }
     $this->addTitleTab('application log');
     $resource = new FileReader(new ConfigObject(array('filename' => Config::app()->get('logging', 'file'), 'fields' => '/(?<!.)(?<datetime>[0-9]{4}(?:-[0-9]{2}){2}' . 'T[0-9]{2}(?::[0-9]{2}){2}(?:[\\+\\-][0-9]{2}:[0-9]{2})?)' . ' - (?<loglevel>[A-Za-z]+) - (?<message>.*)(?!.)/msS')));
     $this->view->logData = $resource->select()->order('DESC');
     $this->setupLimitControl();
     $this->setupPaginationControl($this->view->logData);
 }
开发者ID:JakobGM,项目名称:icingaweb2,代码行数:14,代码来源:ListController.php

示例7: __construct

 /**
  * Create a new authentication chain from config
  *
  * @param Config $config User backends configuration
  */
 public function __construct(Config $config = null)
 {
     if ($config === null) {
         try {
             $this->config = Config::app(static::AUTHENTICATION_CONFIG);
         } catch (NotReadableError $e) {
             $this->config = new Config();
             $this->error = static::EPERM;
         }
     } else {
         $this->config = $config;
     }
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:18,代码来源:AuthChain.php

示例8: indexAction

 /**
  * Show form to adjust user preferences
  */
 public function indexAction()
 {
     $storeConfig = Config::app()->getSection('preferences');
     $user = $this->getRequest()->getUser();
     $form = new PreferenceForm();
     $form->setPreferences($user->getPreferences());
     if ($storeConfig->get('store', 'ini') !== 'none') {
         $form->setStore(PreferencesStore::create($storeConfig, $user));
     }
     $form->handleRequest();
     $this->view->form = $form;
     $this->getTabs()->activate('preferences');
 }
开发者ID:xert,项目名称:icingaweb2,代码行数:16,代码来源:PreferenceController.php

示例9: indexAction

 /**
  * Show form to adjust user preferences
  */
 public function indexAction()
 {
     $config = Config::app()->getSection('global');
     $user = $this->getRequest()->getUser();
     $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('preferences');
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:16,代码来源:PreferenceController.php

示例10: getMainConfig

 private function getMainConfig($file = null)
 {
     if ($file === null) {
         if ($this->config === null) {
             $this->config = Config::app();
         }
         return $this->config;
     } else {
         if (!array_key_exists($file, $this->configs)) {
             $this->configs[$file] = Config::module($module, $file);
         }
         return $this->configs[$file];
     }
     return $this->config;
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:15,代码来源:Command.php

示例11: getGroupsByUsername

 /**
  * Return a list of groups for an username
  *
  * @param   string  $username
  *
  * @return  array
  */
 public function getGroupsByUsername($username)
 {
     $groups = array();
     try {
         $config = Config::app('memberships');
     } catch (NotReadableError $e) {
         return $groups;
     }
     foreach ($config as $section) {
         $users = String::trimSplit($section->users);
         if (in_array($username, $users)) {
             $groups = array_merge($groups, String::trimSplit($section->groups));
         }
     }
     return $groups;
 }
开发者ID:vbereza,项目名称:icinga2-migration,代码行数:23,代码来源:Membership.php

示例12: createResourcesIni

 protected function createResourcesIni()
 {
     $resourceConfig = $this->data['resourceConfig'];
     $resourceName = $resourceConfig['name'];
     unset($resourceConfig['name']);
     try {
         $config = Config::app('resources', true);
         $config->setSection($resourceName, $resourceConfig);
         $config->saveIni();
     } catch (Exception $e) {
         $this->resourcesIniError = $e;
         return false;
     }
     $this->resourcesIniError = false;
     return true;
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:16,代码来源:BackendStep.php

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

示例14: savePreferences

 protected function savePreferences(array $preferences)
 {
     $session = Session::getSession();
     $currentPreferences = $session->user->getPreferences();
     foreach ($preferences as $key => $value) {
         if ($value === null) {
             $currentPreferences->remove($key);
         } else {
             $currentPreferences->{$key} = $value;
         }
     }
     $session->write();
     if (($preferencesConfig = IcingaConfig::app()->preferences) === null) {
         throw new ConfigurationError('Cannot save preferences changes since you\'ve not configured a preferences backend');
     }
     $store = PreferencesStore::create($preferencesConfig, $session->user);
     $store->load();
     // Necessary for patching existing preferences
     $store->save($currentPreferences);
 }
开发者ID:vbereza,项目名称:icinga2-migration,代码行数:20,代码来源:BasePreferenceController.php

示例15: assertResourcesExist

 /**
  * Check if the existing resources are set. If not, load them from resources.ini
  *
  * @throws  ConfigurationError
  */
 private static function assertResourcesExist()
 {
     if (self::$resources === null) {
         self::$resources = Config::app('resources');
     }
 }
开发者ID:0svald,项目名称:icingaweb2,代码行数:11,代码来源:ResourceFactory.php


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