Update usage examples in readme, minor fixes in travis configuration and gitattributes

This commit is contained in:
Robbie Averill 2017-08-28 10:57:30 +12:00
parent c5f0827c2e
commit 37dde110c9
4 changed files with 55 additions and 37 deletions

1
.gitattributes vendored
View File

@ -4,3 +4,4 @@
/.gitignore export-ignore /.gitignore export-ignore
/.travis.yml export-ignore /.travis.yml export-ignore
/.scrutinizer.yml export-ignore /.scrutinizer.yml export-ignore
/codecov.yml export-ignore

View File

@ -25,7 +25,7 @@ before_script:
script: script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi - 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 [[ $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: after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi

View File

@ -39,17 +39,21 @@ spam protection hooks with that protector.
*mysite/_config/spamprotection.yml* *mysite/_config/spamprotection.yml*
```yaml
--- ---
name: spamprotection name: spamprotection
--- ---
FormSpamProtectionExtension: SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension:
default_spam_protector: MollomSpamProtector default_spam_protector: MollomSpamProtector
```
To add spam protection to your form instance call `enableSpamProtection`. To add spam protection to your form instance call `enableSpamProtection`.
```php
// your existing form code // your existing form code
$form = new Form( .. ); $form = new Form(/* .. */);
$form->enableSpamProtection(); $form->enableSpamProtection();
```
The logic to perform the actual spam validation is controlled by each of the The logic to perform the actual spam validation is controlled by each of the
individual `SpamProtector` implementation since they each require a different 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. `enableSpamProtection` takes a hash of optional configuration values.
```php
$form->enableSpamProtection(array( $form->enableSpamProtection(array(
'protector' => 'MathSpamProtector', 'protector' => MathSpamProtector::class,
'name' => 'Captcha' 'name' => 'Captcha'
)); ));
```
Options to configure are: Options to configure are:
@ -76,6 +82,7 @@ Options to configure are:
*`mapping`* an array mapping of the Form fields to the standardized list of *`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: field names. The list of standardized fields to pass to the spam protector are:
```
title title
body body
contextUrl contextUrl
@ -85,6 +92,7 @@ field names. The list of standardized fields to pass to the spam protector are:
authorUrl authorUrl
authorIp authorIp
authorId authorId
```
## Defining your own `SpamProtector` ## Defining your own `SpamProtector`
@ -95,20 +103,24 @@ in charge of the validation process.
<?php <?php
class CustomSpamProtector implements SpamProtector { use CaptchaField;
use SilverStripe\SpamProtection\SpamProtector;
public function getFormField($name = null, $title = null, $value = null) { class CustomSpamProtector implements SpamProtector
// CaptchaField is a imagined class which has some functionality. {
public function getFormField($name = null, $title = null, $value = null)
{
// CaptchaField is an imagined class which has some functionality.
// See silverstripe-mollom module for an example. // See silverstripe-mollom module for an example.
return new CaptchaField($name, $title, $value); return new CaptchaField($name, $title, $value);
} }
} }
```
## Using Spam Protection with User Forms ## Using Spam Protection with User Forms
This module provides an EditableSpamProtectionField wrapper which you can add This module provides an `EditableSpamProtectionField` wrapper which you can add
to your UserForm instances. After installing this module and running /dev/build to your UserForm instances. After installing this module and running `/dev/build`
to rebuild the database, your Form Builder interface will have an option for to rebuild the database, your Form Builder interface will have an option for
`Spam Protection Field`. The type of spam protection used will be based on your `Spam Protection Field`. The type of spam protection used will be based on your
currently selected SpamProtector instance. currently selected SpamProtector instance.
@ -119,8 +131,13 @@ Spam protection is useful to provide but in some cases we do not want to require
the developer to use spam protection. In that case, modules can provide the the developer to use spam protection. In that case, modules can provide the
following pattern following pattern
$form = new Form(..); ```php
use SilverStripe\Forms\Form;
use SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension;
if($form->hasExtension('FormSpamProtectionExtension')) { $form = new Form(/* .. */);
if ($form->hasExtension(FormSpamProtectionExtension::class)) {
$form->enableSpamProtection(); $form->enableSpamProtection();
} }
```

View File

@ -5,7 +5,7 @@
<filter> <filter>
<whitelist addUncoveredFilesFromWhitelist="true"> <whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/.</directory> <directory suffix=".php">code/</directory>
<exclude> <exclude>
<directory suffix=".php">tests/</directory> <directory suffix=".php">tests/</directory>
</exclude> </exclude>