Use Inspection API in LdapResourceForm

refs #9630
This commit is contained in:
Matthias Jentsch 2015-07-15 19:32:12 +02:00
parent 276aa43aa2
commit cf8b760ade
2 changed files with 14 additions and 13 deletions

View File

@ -154,19 +154,17 @@ class LdapResourceForm extends Form
*/
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;
$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()
));
}
return true;
// TODO: display diagnostics in $result->toArray() to the user
return ! $result->hasError();
}
}

View File

@ -945,7 +945,7 @@ class LdapConnection implements Selectable, Inspectable
/**
* Prepare and establish a connection with the LDAP server
*
* @param Inspection $info Optional inspection to fill with diagnosis info
* @param Inspection $info Optional inspection to fill with diagnostic info
*
* @return resource A LDAP link identifier
*
@ -1090,6 +1090,9 @@ class LdapConnection implements Selectable, Inspectable
/**
* Inspect if this LDAP Connection is working as expected
*
* Check if connection, bind and encryption is working as expected and get additional
* information about the used
*
* @return Inspection Inspection result
*/
public function inspect()