FEAT: add throw_exception_on_missing_protector flag to disable exception

This commit is contained in:
Will Rossiter 2023-09-13 06:53:24 +12:00
parent fa8366e706
commit 2e6fbf08aa
No known key found for this signature in database
GPG Key ID: 7FD2A809B22259EF
1 changed files with 15 additions and 1 deletions

View File

@ -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'])) {