本文整理汇总了PHP中Icinga\Web\Form::addError方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::addError方法的具体用法?PHP Form::addError怎么用?PHP Form::addError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Icinga\Web\Form
的用法示例。
在下文中一共展示了Form::addError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: 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();
}
示例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)
{
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;
}
示例5: setupPage
/**
* @see Wizard::setupPage()
*/
public function setupPage(Form $page, Request $request)
{
if ($page->getName() === 'setup_requirements') {
$page->setRequirements($this->getRequirements());
} elseif ($page->getName() === 'setup_monitoring_summary') {
$page->setSummary($this->getSetup()->getSummary());
$page->setSubjectTitle(mt('monitoring', 'the monitoring module', 'setup.summary.subject'));
} elseif ($this->getDirection() === static::FORWARD && ($page->getName() === 'setup_monitoring_ido' || $page->getName() === 'setup_monitoring_livestatus')) {
if (($dbResourceData = $this->getPageData('setup_db_resource')) !== null && $dbResourceData['name'] === $request->getPost('name') || ($ldapResourceData = $this->getPageData('setup_ldap_resource')) !== null && $ldapResourceData['name'] === $request->getPost('name')) {
$page->addError(mt('monitoring', 'The given resource name is already in use.'));
}
}
}
示例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;
}
示例7: 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)
{
/**
* @var $result Inspection
*/
$result = UserBackend::create(null, new ConfigObject($form->getValues()))->inspect();
if ($result->hasError()) {
$form->addError($result->getError());
}
// TODO: display diagnostics in $result->toArray() to the user
return !$result->hasError();
}
示例8: setupPage
/**
* @see Wizard::setupPage()
*/
public function setupPage(Form $page, Request $request)
{
if ($page->getName() === 'setup_requirements') {
$page->setWizard($this);
} elseif ($page->getName() === 'setup_preferences_type') {
$authData = $this->getPageData('setup_authentication_type');
if ($authData['type'] === 'db') {
$page->create()->getElement('store')->setValue('db');
$page->addDescription(mt('setup', 'Note that choosing "Database" causes Icinga Web 2 to use the same database as for authentication.'));
}
} elseif ($page->getName() === 'setup_authentication_backend') {
$authData = $this->getPageData('setup_authentication_type');
if ($authData['type'] === 'db') {
$page->setResourceConfig($this->getPageData('setup_db_resource'));
} elseif ($authData['type'] === 'ldap') {
$page->setResourceConfig($this->getPageData('setup_ldap_resource'));
$suggestions = $this->getPageData('setup_ldap_discovery');
if (isset($suggestions['backend'])) {
$page->populate($suggestions['backend']);
}
}
/*} elseif ($page->getName() === 'setup_ldap_discovery_confirm') {
$page->setResourceConfig($this->getPageData('setup_ldap_discovery'));*/
} elseif ($page->getName() === 'setup_admin_account') {
$page->setBackendConfig($this->getPageData('setup_authentication_backend'));
$authData = $this->getPageData('setup_authentication_type');
if ($authData['type'] === 'db') {
$page->setResourceConfig($this->getPageData('setup_db_resource'));
} elseif ($authData['type'] === 'ldap') {
$page->setResourceConfig($this->getPageData('setup_ldap_resource'));
}
} elseif ($page->getName() === 'setup_database_creation') {
$page->setDatabaseSetupPrivileges(array_unique(array_merge($this->databaseCreationPrivileges, $this->databaseSetupPrivileges)));
$page->setDatabaseUsagePrivileges($this->databaseUsagePrivileges);
$page->setResourceConfig($this->getPageData('setup_db_resource'));
} elseif ($page->getName() === 'setup_summary') {
$page->setSubjectTitle('Icinga Web 2');
$page->setSummary($this->getSetup()->getSummary());
} elseif ($page->getName() === 'setup_db_resource') {
$ldapData = $this->getPageData('setup_ldap_resource');
if ($ldapData !== null && $request->getPost('name') === $ldapData['name']) {
$page->addError(mt('setup', 'The given resource name must be unique and is already in use by the LDAP resource'));
}
} elseif ($page->getName() === 'setup_ldap_resource') {
$dbData = $this->getPageData('setup_db_resource');
if ($dbData !== null && $request->getPost('name') === $dbData['name']) {
$page->addError(mt('setup', 'The given resource name must be unique and is already in use by the database resource'));
}
$suggestion = $this->getPageData('setup_ldap_discovery');
if (isset($suggestion['resource'])) {
$page->populate($suggestion['resource']);
}
} elseif ($page->getName() === 'setup_authentication_type' && $this->getDirection() === static::FORWARD) {
$authData = $this->getPageData($page->getName());
if ($authData !== null && $request->getPost('type') !== $authData['type']) {
// Drop any existing page data in case the authentication type has changed,
// otherwise it will conflict with other forms that depend on this one
$pageData =& $this->getPageData();
unset($pageData['setup_admin_account']);
unset($pageData['setup_authentication_backend']);
}
}
}
示例9: 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 {
$ldapUserBackend = UserBackend::create(null, new ConfigObject($form->getValues()));
$ldapUserBackend->assertAuthenticationPossible();
} catch (AuthenticationException $e) {
if (($previous = $e->getPrevious()) !== null) {
$form->addError($previous->getMessage());
} else {
$form->addError($e->getMessage());
}
return false;
} catch (Exception $e) {
$form->addError(sprintf($form->translate('Unable to validate authentication: %s'), $e->getMessage()));
return false;
}
return true;
}
示例10: isValidIdoSchema
/**
* Validate the ido instance schema resource
*
* @param Form $form
* @param ConfigObject $resourceConfig
*
* @return bool Whether validation succeeded or not
*/
public static function isValidIdoSchema(Form $form, ConfigObject $resourceConfig)
{
try {
$resource = ResourceFactory::createResource($resourceConfig);
$result = $resource->select()->from('icinga_dbversion', array('version'));
$result->fetchOne();
} catch (Exception $e) {
$form->addError($form->translate('IDO schema validation failed, it looks like that the IDO schema is missing in the given database.'));
return false;
}
return true;
}