diff --git a/.gitattributes b/.gitattributes index 475f5f2..89eb187 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,3 +4,4 @@ /.gitignore export-ignore /.travis.yml export-ignore /.scrutinizer.yml export-ignore +/codecov.yml export-ignore diff --git a/.travis.yml b/.travis.yml index c73141d..eae8a3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ before_script: script: - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=framework/phpcs.xml.dist src/ tests/ ; fi + - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=framework/phpcs.xml.dist code/ tests/ ; fi after_success: - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi diff --git a/README.md b/README.md index 98e9711..bbb8047 100644 --- a/README.md +++ b/README.md @@ -39,17 +39,21 @@ spam protection hooks with that protector. *mysite/_config/spamprotection.yml* - --- - name: spamprotection - --- - FormSpamProtectionExtension: - default_spam_protector: MollomSpamProtector +```yaml +--- +name: spamprotection +--- +SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension: + default_spam_protector: MollomSpamProtector +``` To add spam protection to your form instance call `enableSpamProtection`. - // your existing form code - $form = new Form( .. ); - $form->enableSpamProtection(); +```php +// your existing form code +$form = new Form(/* .. */); +$form->enableSpamProtection(); +``` The logic to perform the actual spam validation is controlled by each of the individual `SpamProtector` implementation since they each require a different @@ -59,10 +63,12 @@ implementation client side or server side. `enableSpamProtection` takes a hash of optional configuration values. - $form->enableSpamProtection(array( - 'protector' => 'MathSpamProtector', - 'name' => 'Captcha' - )); +```php +$form->enableSpamProtection(array( + 'protector' => MathSpamProtector::class, + 'name' => 'Captcha' +)); +``` Options to configure are: @@ -76,15 +82,17 @@ Options to configure are: *`mapping`* an array mapping of the Form fields to the standardized list of field names. The list of standardized fields to pass to the spam protector are: - title - body - contextUrl - contextTitle - authorName - authorMail - authorUrl - authorIp - authorId +``` +title +body +contextUrl +contextTitle +authorName +authorMail +authorUrl +authorIp +authorId +``` ## Defining your own `SpamProtector` @@ -93,22 +101,26 @@ be set as the spam protector. The `getFormField()` method returns the `FormField` to be inserted into the `Form`. The `FormField` returned should be in charge of the validation process. - hasExtension('FormSpamProtectionExtension')) { - $form->enableSpamProtection(); - } +$form = new Form(/* .. */); + +if ($form->hasExtension(FormSpamProtectionExtension::class)) { + $form->enableSpamProtection(); +} +``` diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d6d5263..4cd5d19 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,7 +5,7 @@ - src/. + code/ tests/