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) public static function isValidResource(Form $form)
{ {
try { $result = ResourceFactory::createResource(new ConfigObject($form->getValues()))->inspect();
$resource = ResourceFactory::createResource(new ConfigObject($form->getValues())); if ($result->hasError()) {
$resource->bind(); $form->addError(sprintf(
} catch (Exception $e) { '%s (%s)',
$msg = $form->translate('Connectivity validation failed, connection to the given resource not possible.'); $form->translate('Connectivity validation failed, connection to the given resource not possible.'),
if (($error = $e->getMessage())) { $result->getError()
$msg .= ' (' . $error . ')'; ));
}
$form->addError($msg);
return false;
} }
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 * 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 * @return resource A LDAP link identifier
* *
@ -1090,6 +1090,9 @@ class LdapConnection implements Selectable, Inspectable
/** /**
* Inspect if this LDAP Connection is working as expected * 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 * @return Inspection Inspection result
*/ */
public function inspect() public function inspect()