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


PHP ResourceFactory::createResource方法代码示例

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


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

示例1: isValidResource

 /**
  * Validate the resource configuration by trying to connect with it
  *
  * @param   Form    $form   The form to fetch the configuration values from
  *
  * @return  bool            Whether validation succeeded or not
  */
 public static function isValidResource(Form $form)
 {
     $result = ResourceFactory::createResource(new ConfigObject($form->getValues()))->inspect();
     if ($result->hasError()) {
         $form->addError(sprintf('%s (%s)', $form->translate('Connectivity validation failed, connection to the given resource not possible.'), $result->getError()));
     }
     // TODO: display diagnostics in $result->toArray() to the user
     return !$result->hasError();
 }
开发者ID:bebehei,项目名称:icingaweb2,代码行数:16,代码来源:LdapResourceForm.php

示例2: isValidUserBackend

 /**
  * Validate the configuration by creating a backend and requesting the user count
  *
  * @param   Form    $form   The form to fetch the configuration values from
  *
  * @return  bool            Whether validation succeeded or not
  */
 public static function isValidUserBackend(Form $form)
 {
     $backend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
     $result = $backend->inspect();
     if ($result->hasError()) {
         $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $result->getError()));
     }
     // TODO: display diagnostics in $result->toArray() to the user
     return !$result->hasError();
 }
开发者ID:bebehei,项目名称:icingaweb2,代码行数:17,代码来源:DbBackendForm.php

示例3: isValidResource

 /**
  * Validate the resource configuration by trying to connect with it
  *
  * @param   Form    $form   The form to fetch the configuration values from
  *
  * @return  bool            Whether validation succeeded or not
  */
 public static function isValidResource(Form $form)
 {
     try {
         $resource = ResourceFactory::createResource(new ConfigObject($form->getValues()));
         $resource->getConnection()->getConnection();
     } catch (Exception $e) {
         $form->addError($form->translate('Connectivity validation failed, connection to the given resource not possible.'));
         return false;
     }
     return true;
 }
开发者ID:hsanjuan,项目名称:icingaweb2,代码行数:18,代码来源:DbResourceForm.php

示例4: createAccount

 protected function createAccount()
 {
     try {
         $backend = new DbUserBackend(ResourceFactory::createResource(new ConfigObject($this->data['adminAccountData']['resourceConfig'])));
         if ($backend->select()->where('user_name', $this->data['adminAccountData']['username'])->count() === 0) {
             $backend->insert('user', array('user_name' => $this->data['adminAccountData']['username'], 'password' => $this->data['adminAccountData']['password'], 'is_active' => true));
         }
     } catch (Exception $e) {
         $this->dbError = $e;
         return false;
     }
     $this->dbError = false;
     return true;
 }
开发者ID:hsanjuan,项目名称:icingaweb2,代码行数:14,代码来源:AuthenticationStep.php

示例5: isValidUserBackend

 /**
  * Validate the configuration by creating a backend and requesting the user count
  *
  * @param   Form    $form   The form to fetch the configuration values from
  *
  * @return  bool            Whether validation succeeded or not
  */
 public static function isValidUserBackend(Form $form)
 {
     try {
         $dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig()));
         if ($dbUserBackend->select()->where('is_active', true)->count() < 1) {
             $form->addError($form->translate('No active users found under the specified database backend'));
             return false;
         }
     } catch (Exception $e) {
         $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $e->getMessage()));
         return false;
     }
     return true;
 }
开发者ID:hsanjuan,项目名称:icingaweb2,代码行数:21,代码来源:DbBackendForm.php

示例6: isValidResource

 /**
  * Validate the resource configuration by trying to connect with it
  *
  * @param   Form    $form   The form to fetch the configuration values from
  *
  * @return  bool            Whether validation succeeded or not
  */
 public static function isValidResource(Form $form)
 {
     try {
         $resource = ResourceFactory::createResource(new ConfigObject($form->getValues()));
         $resource->bind();
     } catch (Exception $e) {
         $msg = $form->translate('Connectivity validation failed, connection to the given resource not possible.');
         if ($error = $e->getMessage()) {
             $msg .= ' (' . $error . ')';
         }
         $form->addError($msg);
         return false;
     }
     return true;
 }
开发者ID:kain64,项目名称:icingaweb2,代码行数:22,代码来源:LdapResourceForm.php

示例7: createMembership

 protected function createMembership()
 {
     try {
         $backend = new DbUserGroupBackend(ResourceFactory::createResource(new ConfigObject($this->data['resourceConfig'])));
         $groupName = mt('setup', 'Administrators', 'setup.role.name');
         $userName = $this->data['username'];
         if ($backend->select()->from('group_membership')->where('group_name', $groupName)->where('user_name', $userName)->count() === 0) {
             $backend->insert('group_membership', array('group_name' => $groupName, 'user_name' => $userName));
             $this->memberError = false;
         }
     } catch (Exception $e) {
         $this->memberError = $e;
         return false;
     }
     return true;
 }
开发者ID:NerdGZ,项目名称:icingaweb2,代码行数:16,代码来源:UserGroupStep.php

示例8: inspectResource

 /**
  * Create a resource by using the given form's values and return its inspection results
  *
  * @param   Form    $form
  *
  * @return  Inspection
  */
 public static function inspectResource(Form $form)
 {
     if ($form->getValue('type') !== 'ssh') {
         $resource = ResourceFactory::createResource(new ConfigObject($form->getValues()));
         if ($resource instanceof Inspectable) {
             return $resource->inspect();
         }
     }
 }
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:16,代码来源:ResourceConfigForm.php

示例9: isValidIdoInstance

 /**
  * Return whether a single icinga instance is writing to the given resource
  *
  * @param   Form            $form
  * @param   ConfigObject    $resourceConfig
  *
  * @return  bool                                True if it's a single instance, false if none
  *                                              or multiple instances are writing to it
  */
 public static function isValidIdoInstance(Form $form, ConfigObject $resourceConfig)
 {
     $db = ResourceFactory::createResource($resourceConfig);
     $rowCount = $db->select()->from('icinga_instances')->count();
     if ($rowCount === 0) {
         $form->warning($form->translate('There is currently no icinga instance writing to the IDO. Make sure ' . 'that a icinga instance is configured and able to write to the IDO.'));
         return false;
     } elseif ($rowCount > 1) {
         $form->warning($form->translate('There is currently more than one icinga instance writing to the IDO. You\'ll see all objects from all' . ' instances without any differentation. If this is not desired, consider setting up a separate IDO' . ' for each instance.'));
         return false;
     }
     return true;
 }
开发者ID:bebehei,项目名称:icingaweb2,代码行数:22,代码来源:BackendConfigForm.php

示例10: createDbConnectionFor

 /**
  * Creates an array of Icinga\Data\Db\DbConnection
  *
  * @param   string $name
  *
  * @return  array
  */
 protected function createDbConnectionFor($name)
 {
     try {
         $conn = ResourceFactory::createResource($this->createDbConfigFor($name));
     } catch (Exception $e) {
         $conn = $e->getMessage();
     }
     return array(array($conn));
 }
开发者ID:hsanjuan,项目名称:icingaweb2,代码行数:16,代码来源:BaseTestCase.php

示例11: 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);
     }
     if ($backendConfig->resource instanceof ConfigObject) {
         $resource = ResourceFactory::createResource($backendConfig->resource);
     } else {
         $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:hsanjuan,项目名称:icingaweb2,代码行数:74,代码来源:UserBackend.php

示例12: create

 public static function create($name, Zend_Config $backendConfig)
 {
     if ($backendConfig->name !== null) {
         $name = $backendConfig->name;
     }
     if (isset($backendConfig->class)) {
         // Use a custom backend class, this is only useful for testing
         if (!class_exists($backendConfig->class)) {
             throw new ConfigurationError('Authentication configuration for backend "' . $name . '" defines an invalid backend' . ' class. Backend class "' . $backendConfig->class . '" not found');
         }
         return new $backendConfig->class($backendConfig);
     }
     if ($name === 'autologin') {
         $backend = new AutoLoginBackend($backendConfig);
         $backend->setName($name);
         return $backend;
     }
     if ($backendConfig->resource === null) {
         throw new ConfigurationError('Authentication configuration for backend "' . $name . '" is missing the resource directive');
     }
     if (($backendType = $backendConfig->backend) === null) {
         throw new ConfigurationError('Authentication configuration for backend "' . $name . '" is missing the backend directive');
     }
     try {
         $resourceConfig = ResourceFactory::getResourceConfig($backendConfig->resource);
     } catch (ProgrammingError $e) {
         throw new ConfigurationError('Resources not set up. Please contact your Icinga Web administrator');
     }
     $resource = ResourceFactory::createResource($resourceConfig);
     switch (strtolower($backendType)) {
         case 'db':
             $backend = new DbUserBackend($resource);
             break;
         case 'msldap':
             $backend = new LdapUserBackend($resource, $backendConfig->get('user_class', 'user'), $backendConfig->get('user_name_attribute', 'sAMAccountName'));
             break;
         case 'ldap':
             if (($userClass = $backendConfig->user_class) === null) {
                 throw new ConfigurationError('Authentication configuration for backend "' . $name . '" is missing the user_class directive');
             }
             if (($userNameAttribute = $backendConfig->user_name_attribute) === null) {
                 throw new ConfigurationError('Authentication configuration for backend "' . $name . '" is missing the user_name_attribute directive');
             }
             $backend = new LdapUserBackend($resource, $userClass, $userNameAttribute);
             break;
         default:
             throw new ConfigurationError('Authentication configuration for backend "' . $name . '" defines an invalid backend' . ' type. Backend type "' . $backendType . '" is not supported');
     }
     $backend->setName($name);
     return $backend;
 }
开发者ID:vbereza,项目名称:icinga2-migration,代码行数:51,代码来源:UserBackend.php

示例13: isValidIdoInstance

 /**
  * Validate the ido instance availability
  *
  * @param   Form            $form
  * @param   ConfigObject    $resourceConfig
  *
  * @return  bool                                Whether validation succeeded or not
  */
 public static function isValidIdoInstance(Form $form, ConfigObject $resourceConfig)
 {
     $resource = ResourceFactory::createResource($resourceConfig);
     $result = $resource->select()->from('icinga_instances', array('instance_name'));
     $instances = $result->fetchAll();
     if (count($instances) === 1) {
         return true;
     } elseif (count($instances) > 1) {
         $form->warning($form->translate('IDO instance validation failed, because there are multiple instances available.'));
         return false;
     }
     $form->error($form->translate('IDO instance validation failed, because there is no IDO instance available.'));
     return false;
 }
开发者ID:xert,项目名称:icingaweb2,代码行数:22,代码来源:BackendConfigForm.php


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