本文整理汇总了PHP中Icinga\Data\ResourceFactory类的典型用法代码示例。如果您正苦于以下问题:PHP ResourceFactory类的具体用法?PHP ResourceFactory怎么用?PHP ResourceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: connection
protected function connection()
{
if ($this->connection === null) {
$this->connection = ResourceFactory::create($this->settings['resource']);
}
return $this->connection;
}
开发者ID:dgoeger,项目名称:icingadirector,代码行数:7,代码来源:ImportSourceLdap.php
示例2: createbackendAction
/**
* Create a new monitoring backend
*/
public function createbackendAction()
{
$form = new BackendConfigForm();
$form->setRedirectUrl('monitoring/config');
$form->setTitle($this->translate('Create New Monitoring Backend'));
$form->setIniConfig($this->Config('backends'));
try {
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
} catch (ConfigurationError $e) {
if ($this->hasPermission('config/application/resources')) {
Notification::error($e->getMessage());
$this->redirectNow('config/createresource');
}
throw $e;
// No permission for resource configuration, show the error
}
$form->setOnSuccess(function (BackendConfigForm $form) {
try {
$form->add(array_filter($form->getValues()));
} catch (Exception $e) {
$form->error($e->getMessage());
return false;
}
if ($form->save()) {
Notification::success(t('Monitoring backend successfully created'));
return true;
}
return false;
});
$form->handleRequest();
$this->view->form = $form;
$this->render('form');
}
开发者ID:kobmaki,项目名称:icingaweb2,代码行数:36,代码来源:ConfigController.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: 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
示例5: getDatabaseResourceNames
/**
* Return the names of all configured database resources
*
* @return array
*/
protected function getDatabaseResourceNames()
{
$names = array();
foreach (ResourceFactory::getResourceConfigs() as $name => $config) {
if (strtolower($config->type) === 'db') {
$names[] = $name;
}
}
return $names;
}
开发者ID:NerdGZ,项目名称:icingaweb2,代码行数:15,代码来源:DbUserGroupBackendForm.php
示例6: enumResources
protected static function enumResources($type)
{
$resources = array();
foreach (ResourceFactory::getResourceConfigs() as $name => $resource) {
if ($resource->type === $type && self::resourceIsAllowed($name)) {
$resources[$name] = $name;
}
}
return $resources;
}
开发者ID:dgoeger,项目名称:icingadirector,代码行数:10,代码来源:Util.php
示例7: hasResources
/**
* Check whether ssh identity resources exists or not
*
* @return boolean
*/
public function hasResources()
{
$resourceConfig = ResourceFactory::getResourceConfigs();
foreach ($resourceConfig as $name => $resource) {
if ($resource->type === 'ssh') {
return true;
}
}
return false;
}
开发者ID:NerdGZ,项目名称:icingaweb2,代码行数:15,代码来源:RemoteInstanceForm.php
示例8: createbackendAction
/**
* Display a form to create a new backend
*/
public function createbackendAction()
{
$form = new BackendConfigForm();
$form->setTitle($this->translate('Add New Backend'));
$form->setIniConfig($this->Config('backends'));
$form->setResourceConfig(ResourceFactory::getResourceConfigs());
$form->setRedirectUrl('monitoring/config');
$form->handleRequest();
$this->view->form = $form;
}
开发者ID:xert,项目名称:icingaweb2,代码行数:13,代码来源:ConfigController.php
示例9: 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
示例10: 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
示例11: createElements
/**
* @see Form::createElements()
*/
public function createElements(array $formData)
{
$this->addElement('text', 'global_module_path', array('label' => $this->translate('Module Path'), 'required' => true, 'value' => implode(':', Icinga::app()->getModuleManager()->getModuleDirs()), 'description' => $this->translate('Contains the directories that will be searched for available modules, separated by ' . 'colons. Modules that don\'t exist in these directories can still be symlinked in ' . 'the module folder, but won\'t show up in the list of disabled modules.')));
$this->addElement('select', 'preferences_store', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('User Preference Storage Type'), 'multiOptions' => array('ini' => $this->translate('File System (INI Files)'), 'db' => $this->translate('Database'), 'none' => $this->translate('Don\'t Store Preferences'))));
if (isset($formData['preferences_store']) && $formData['preferences_store'] === 'db') {
$backends = array();
foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) {
if ($resource['type'] === 'db') {
$backends[$name] = $name;
}
}
$this->addElement('select', 'preferences_resource', array('required' => true, 'multiOptions' => $backends, 'label' => $this->translate('Database Connection')));
}
return $this;
}
开发者ID:xert,项目名称:icingaweb2,代码行数:18,代码来源:ApplicationConfigForm.php
示例12: loadResources
/**
* Load all available ssh identity resources
*
* @return $this
*
* @throws \Icinga\Exception\ConfigurationError
*/
public function loadResources()
{
$resourceConfig = ResourceFactory::getResourceConfigs();
$resources = array();
foreach ($resourceConfig as $name => $resource) {
if ($resource->type === 'ssh') {
$resources['ssh'][$name] = $name;
}
}
if (empty($resources)) {
throw new ConfigurationError($this->translate('Could not find any valid monitoring instance resources'));
}
$this->resources = $resources;
return $this;
}
开发者ID:hsanjuan,项目名称:icingaweb2,代码行数:22,代码来源:RemoteInstanceForm.php
示例13: 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
示例14: 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
示例15: createElements
/**
* @see Form::createElements()
*/
public function createElements(array $formData)
{
$this->addElement('checkbox', 'global_show_stacktraces', array('required' => true, 'value' => true, 'label' => $this->translate('Show Stacktraces'), 'description' => $this->translate('Set whether to show an exception\'s stacktrace by default. This can also' . ' be set in a user\'s preferences with the appropriate permission.')));
$this->addElement('text', 'global_module_path', array('label' => $this->translate('Module Path'), 'required' => true, 'value' => implode(':', Icinga::app()->getModuleManager()->getModuleDirs()), 'description' => $this->translate('Contains the directories that will be searched for available modules, separated by ' . 'colons. Modules that don\'t exist in these directories can still be symlinked in ' . 'the module folder, but won\'t show up in the list of disabled modules.')));
$this->addElement('select', 'global_config_backend', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('User Preference Storage Type'), 'multiOptions' => array('ini' => $this->translate('File System (INI Files)'), 'db' => $this->translate('Database'), 'none' => $this->translate('Don\'t Store Preferences'))));
if (isset($formData['global_config_backend']) && $formData['global_config_backend'] === 'db') {
$backends = array();
foreach (ResourceFactory::getResourceConfigs()->toArray() as $name => $resource) {
if ($resource['type'] === 'db') {
$backends[$name] = $name;
}
}
$this->addElement('select', 'global_config_resource', array('required' => true, 'multiOptions' => $backends, 'label' => $this->translate('Database Connection')));
}
$this->addElement('text', 'datetime_format', array('label' => $this->translate('Datetime format'), 'required' => true, 'value' => $this->translate('Y-m-d H:i:s'), 'description' => $this->translate('Datetime format for use when displaying timestamps in history views. Uses PHP ' . 'date() format, see PHP documentation for syntax.')));
return $this;
}
开发者ID:ZipRecruiter,项目名称:icingaweb2,代码行数:20,代码来源:ApplicationConfigForm.php
示例16: createElements
/**
* Create and add elements to this form
*
* @param array $formData
*/
public function createElements(array $formData)
{
$isAd = isset($formData['type']) ? $formData['type'] === 'msldap' : false;
$this->addElement('text', 'name', array('required' => true, 'label' => $this->translate('Backend Name'), 'description' => $this->translate('The name of this authentication provider that is used to differentiate it from others.')));
$this->addElement('select', 'resource', array('required' => true, 'label' => $this->translate('LDAP Connection'), 'description' => $this->translate('The LDAP connection to use for authenticating with this provider.'), 'multiOptions' => !empty($this->resources) ? array_combine($this->resources, $this->resources) : array()));
$baseDn = null;
$hasAdOid = false;
if (!$isAd && !empty($this->resources)) {
$this->addElement('button', 'discovery_btn', array('type' => 'submit', 'value' => 'discovery_btn', 'label' => $this->translate('Discover', 'A button to discover LDAP capabilities'), 'title' => $this->translate('Push to fill in the chosen connection\'s default settings.'), 'decorators' => array(array('ViewHelper', array('separator' => '')), array('HtmlTag', array('tag' => 'div', 'class' => 'element'))), 'formnovalidate' => 'formnovalidate'));
$this->addDisplayGroup(array('resource', 'discovery_btn'), 'connection_discovery', array('decorators' => array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'control-group')))));
if ($this->getElement('discovery_btn')->isChecked()) {
$connection = ResourceFactory::create(isset($formData['resource']) ? $formData['resource'] : reset($this->resources));
try {
$capabilities = $connection->bind()->getCapabilities();
$baseDn = $capabilities->getDefaultNamingContext();
$hasAdOid = $capabilities->isActiveDirectory();
} catch (Exception $e) {
$this->warning(sprintf($this->translate('Failed to discover the chosen LDAP connection: %s'), $e->getMessage()));
}
}
}
if ($isAd || $hasAdOid) {
// ActiveDirectory defaults
$userClass = 'user';
$filter = '!(objectClass=computer)';
$userNameAttribute = 'sAMAccountName';
} else {
// OpenLDAP defaults
$userClass = 'inetOrgPerson';
$filter = null;
$userNameAttribute = 'uid';
}
$this->addElement('text', 'user_class', array('preserveDefault' => true, 'required' => !$isAd, 'ignore' => $isAd, 'disabled' => $isAd ?: null, 'label' => $this->translate('LDAP User Object Class'), 'description' => $this->translate('The object class used for storing users on the LDAP server.'), 'value' => $userClass));
$this->addElement('text', 'filter', array('preserveDefault' => true, 'allowEmpty' => true, 'value' => $filter, 'label' => $this->translate('LDAP Filter'), 'description' => $this->translate('An additional filter to use when looking up users using the specified connection. ' . 'Leave empty to not to use any additional filter rules.'), 'requirement' => $this->translate('The filter needs to be expressed as standard LDAP expression.' . ' (e.g. &(foo=bar)(bar=foo) or foo=bar)'), 'validators' => array(array('Callback', false, array('callback' => function ($v) {
// This is not meant to be a full syntax check. It will just
// ensure that we can safely strip unnecessary parentheses.
$v = trim($v);
return !$v || $v[0] !== '(' || (strpos($v, ')(') !== false ? substr($v, -2) === '))' : substr($v, -1) === ')');
}, 'messages' => array('callbackValue' => $this->translate('The filter is invalid. Please check your syntax.')))))));
$this->addElement('text', 'user_name_attribute', array('preserveDefault' => true, 'required' => !$isAd, 'ignore' => $isAd, 'disabled' => $isAd ?: null, 'label' => $this->translate('LDAP User Name Attribute'), 'description' => $this->translate('The attribute name used for storing the user name on the LDAP server.'), 'value' => $userNameAttribute));
$this->addElement('hidden', 'backend', array('disabled' => true, 'value' => $isAd ? 'msldap' : 'ldap'));
$this->addElement('text', 'base_dn', array('preserveDefault' => true, 'required' => false, 'label' => $this->translate('LDAP Base DN'), 'description' => $this->translate('The path where users can be found on the LDAP server. Leave ' . 'empty to select all users available using the specified connection.'), 'value' => $baseDn));
}
开发者ID:JakobGM,项目名称:icingaweb2,代码行数:48,代码来源:LdapBackendForm.php
示例17: getResource
/**
* Get this backend's internal resource
*
* @return mixed
*/
public function getResource()
{
if ($this->resource === null) {
$this->resource = ResourceFactory::create($this->config->get('resource'));
if ($this->is('ido') && $this->resource->getDbType() !== 'oracle') {
// TODO(el): The resource should set the table prefix
$this->resource->setTablePrefix('icinga_');
}
}
return $this->resource;
}
开发者ID:trigoesrodrigo,项目名称:icingaweb2,代码行数:16,代码来源:MonitoringBackend.php
示例18: 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
示例19: getResourceConfig
/**
* Return the configuration for the chosen resource
*
* @return ConfigObject
*/
public function getResourceConfig()
{
return ResourceFactory::getResourceConfig($this->getValue('resource'));
}
开发者ID:hsanjuan,项目名称:icingaweb2,代码行数:9,代码来源:UserBackendConfigForm.php
示例20: enumResources
protected function enumResources()
{
$resources = array();
$allowed = array('mysql', 'pgsql');
foreach (ResourceFactory::getResourceConfigs() as $name => $resource) {
if ($resource->type === 'db' && in_array($resource->db, $allowed)) {
$resources[$name] = $name;
}
}
return $resources;
}
开发者ID:dgoeger,项目名称:icingadirector,代码行数:11,代码来源:ConfigForm.php
注:本文中的Icinga\Data\ResourceFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论