Skip to content

Commit

Permalink
FEAT: add throw_exception_on_missing_protector flag to disable exception
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Sep 12, 2023
1 parent fa8366e commit 087da64
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Extension/FormSpamProtectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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
Expand All @@ -28,6 +29,13 @@ class FormSpamProtectionExtension extends Extension
*/
private static $default_spam_protector;

/**
* @config
*
* @var bool
*/
private static $throw_exception_on_missing_protector;

/**
* @config
*
Expand Down Expand Up @@ -109,7 +117,13 @@ public function enableSpamProtection($options = [])
$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::get(LoggerInterface::class)->warning(
'No spam protector has been set. Null is not valid value.'
);
}
}

if ($protector && isset($options['mapping'])) {
Expand Down

0 comments on commit 087da64

Please sign in to comment.