FEAT: add throw_exception_on_missing_protector flag to disable exception
This commit is contained in:
parent
fa8366e706
commit
2e6fbf08aa
|
@ -6,6 +6,7 @@ use LogicException;
|
|||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* An extension to the {@link Form} class which provides the method
|
||||
|
@ -28,6 +29,13 @@ class FormSpamProtectionExtension extends Extension
|
|||
*/
|
||||
private static $default_spam_protector;
|
||||
|
||||
/**
|
||||
* @config
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static $throw_exception_on_missing_protector = true;
|
||||
|
||||
/**
|
||||
* @config
|
||||
*
|
||||
|
@ -109,7 +117,13 @@ class FormSpamProtectionExtension extends Extension
|
|||
$protector = self::get_protector($options);
|
||||
|
||||
if ($protector === null) {
|
||||
throw new LogicException('No spam protector has been set. Null is not valid value.');
|
||||
if ($this->config()->get('throw_exception_on_missing_protector')) {
|
||||
throw new LogicException('No spam protector has been set. Null is not valid value.');
|
||||
} else {
|
||||
Injector::inst()->get(LoggerInterface::class)->warning(
|
||||
'No spam protector has been set. Null is not valid value.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($protector && isset($options['mapping'])) {
|
||||
|
|
Loading…
Reference in New Issue