Make isValid* calls of configuration forms being static
This allows a more flexible usage as there is no need to access instance formdata when validating such configuration.
This commit is contained in:
parent
8e48853f4d
commit
0e92e333aa
|
@ -82,7 +82,7 @@ class AutologinBackendForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidAuthenticationBackend(Form $form)
|
||||
public static function isValidAuthenticationBackend(Form $form)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ class DbBackendForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidAuthenticationBackend($this)) {
|
||||
if (false === static::isValidAuthenticationBackend($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ class DbBackendForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidAuthenticationBackend(Form $form)
|
||||
public static function isValidAuthenticationBackend(Form $form)
|
||||
{
|
||||
$element = $form->getElement('resource');
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ class LdapBackendForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidAuthenticationBackend($this)) {
|
||||
if (false === static::isValidAuthenticationBackend($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ class LdapBackendForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidAuthenticationBackend(Form $form)
|
||||
public static function isValidAuthenticationBackend(Form $form)
|
||||
{
|
||||
$element = $form->getElement('resource');
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ class AuthenticationBackendConfigForm extends ConfigForm
|
|||
{
|
||||
if (($el = $this->getElement('force_creation')) === null || false === $el->isChecked()) {
|
||||
$backendForm = $this->getBackendForm($this->getElement('type')->getValue());
|
||||
if (false === $backendForm->isValidAuthenticationBackend($this)) {
|
||||
if (false === $backendForm::isValidAuthenticationBackend($this)) {
|
||||
$this->addElement($this->getForceCreationCheckbox());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ class DbResourceForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidResource($this)) {
|
||||
if (false === static::isValidResource($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class DbResourceForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidResource(Form $form)
|
||||
public static function isValidResource(Form $form)
|
||||
{
|
||||
try {
|
||||
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
|
||||
|
|
|
@ -89,7 +89,7 @@ class LdapResourceForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidResource($this)) {
|
||||
if (false === static::isValidResource($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ class LdapResourceForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidResource(Form $form)
|
||||
public static function isValidResource(Form $form)
|
||||
{
|
||||
try {
|
||||
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
|
||||
|
|
|
@ -50,7 +50,7 @@ class LivestatusResourceForm extends Form
|
|||
*/
|
||||
public function onSuccess(Request $request)
|
||||
{
|
||||
if (false === $this->isValidResource($this)) {
|
||||
if (false === static::isValidResource($this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class LivestatusResourceForm extends Form
|
|||
*
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValidResource(Form $form)
|
||||
public static function isValidResource(Form $form)
|
||||
{
|
||||
try {
|
||||
$resource = ResourceFactory::createResource(new Zend_Config($form->getValues()));
|
||||
|
|
|
@ -135,7 +135,7 @@ class ResourceConfigForm extends ConfigForm
|
|||
{
|
||||
if (($el = $this->getElement('force_creation')) === null || false === $el->isChecked()) {
|
||||
$resourceForm = $this->getResourceForm($this->getElement('type')->getValue());
|
||||
if (method_exists($resourceForm, 'isValidResource') && false === $resourceForm->isValidResource($this)) {
|
||||
if (method_exists($resourceForm, 'isValidResource') && false === $resourceForm::isValidResource($this)) {
|
||||
$this->addElement($this->getForceCreationCheckbox());
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class DbBackendFormTest extends BaseTestCase
|
|||
$form->populate(array('resource' => 'test_db_backend'));
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValidAuthenticationBackend($form),
|
||||
DbBackendForm::isValidAuthenticationBackend($form),
|
||||
'DbBackendForm claims that a valid authentication backend with users is not valid'
|
||||
);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class DbBackendFormTest extends BaseTestCase
|
|||
$form->populate(array('resource' => 'test_db_backend'));
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValidAuthenticationBackend($form),
|
||||
DbBackendForm::isValidAuthenticationBackend($form),
|
||||
'DbBackendForm claims that an invalid authentication backend without users is valid'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class LdapBackendFormTest extends BaseTestCase
|
|||
$form->populate(array('resource' => 'test_ldap_backend'));
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValidAuthenticationBackend($form),
|
||||
LdapBackendForm::isValidAuthenticationBackend($form),
|
||||
'LdapBackendForm claims that a valid authentication backend with users is not valid'
|
||||
);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class LdapBackendFormTest extends BaseTestCase
|
|||
$form->populate(array('resource' => 'test_ldap_backend'));
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValidAuthenticationBackend($form),
|
||||
LdapBackendForm::isValidAuthenticationBackend($form),
|
||||
'LdapBackendForm claims that an invalid authentication backend without users is valid'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -30,10 +30,8 @@ class DbResourceFormTest extends BaseTestCase
|
|||
Mockery::mock()->shouldReceive('getConnection')->atMost()->twice()->andReturn(Mockery::self())->getMock()
|
||||
);
|
||||
|
||||
$form = new DbResourceForm();
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValidResource($form),
|
||||
DbResourceForm::isValidResource(new DbResourceForm()),
|
||||
'ResourceForm claims that a valid db resource is not valid'
|
||||
);
|
||||
}
|
||||
|
@ -48,10 +46,8 @@ class DbResourceFormTest extends BaseTestCase
|
|||
Mockery::mock()->shouldReceive('getConnection')->once()->andThrow('\Exception')->getMock()
|
||||
);
|
||||
|
||||
$form = new DbResourceForm();
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValidResource($form),
|
||||
DbResourceForm::isValidResource(new DbResourceForm()),
|
||||
'ResourceForm claims that an invalid db resource is valid'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -30,10 +30,8 @@ class LdapResourceFormTest extends BaseTestCase
|
|||
Mockery::mock()->shouldReceive('connect')->getMock()
|
||||
);
|
||||
|
||||
$form = new LdapResourceForm();
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValidResource($form),
|
||||
LdapResourceForm::isValidResource(new LdapResourceForm()),
|
||||
'ResourceForm claims that a valid ldap resource is not valid'
|
||||
);
|
||||
}
|
||||
|
@ -48,10 +46,8 @@ class LdapResourceFormTest extends BaseTestCase
|
|||
Mockery::mock()->shouldReceive('connect')->once()->andThrow('\Exception')->getMock()
|
||||
);
|
||||
|
||||
$form = new LdapResourceForm();
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValidResource($form),
|
||||
LdapResourceForm::isValidResource(new LdapResourceForm()),
|
||||
'ResourceForm claims that an invalid ldap resource is valid'
|
||||
);
|
||||
}
|
||||
|
|
|
@ -31,10 +31,8 @@ class LivestatusResourceFormTest extends BaseTestCase
|
|||
->shouldReceive('disconnect')->getMock()
|
||||
);
|
||||
|
||||
$form = new LivestatusResourceForm();
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValidResource($form),
|
||||
LivestatusResourceForm::isValidResource(new LivestatusResourceForm()),
|
||||
'ResourceForm claims that a valid livestatus resource is not valid'
|
||||
);
|
||||
}
|
||||
|
@ -49,10 +47,8 @@ class LivestatusResourceFormTest extends BaseTestCase
|
|||
Mockery::mock()->shouldReceive('connect')->once()->andThrow('\Exception')->getMock()
|
||||
);
|
||||
|
||||
$form = new LivestatusResourceForm();
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValidResource($form),
|
||||
LivestatusResourceForm::isValidResource(new LivestatusResourceForm()),
|
||||
'ResourceForm claims that an invalid livestatus resource is valid'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue