Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the documentation and moved it to coucous.io
- Loading branch information
Adrian Miu
committed
Jun 20, 2015
1 parent
1d48094
commit d291e86
Showing
15 changed files
with
471 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/docs export-ignore | ||
/tests export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.scrutinizer.yml export-ignore | ||
/.travis.yml export-ignore | ||
/couscous.yml export-ignore | ||
/index.md export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
INSTALL.txt | ||
LICENSE.txt | ||
README.txt | ||
tests/report | ||
build | ||
/.settings | ||
/.buildpath | ||
/.project | ||
.idea/ | ||
docs/.couscous | ||
docs/couscous.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
template: | ||
url: https://github.com/siriusphp/Template-ReadTheDocs | ||
|
||
# List of directories to exclude from the processing (default contains "vendor" and "website") | ||
# Paths are relative to the repository root | ||
exclude: | ||
- website | ||
- vendor | ||
- test | ||
- src | ||
- build | ||
|
||
# Base URL of the published website (no "/" at the end!) | ||
# You are advised to set and use this variable to write your links in the HTML layouts | ||
baseUrl: http://www.sirius.ro/php/sirius/filtration | ||
|
||
projectName: Sirius\Filtration | ||
title: Sirius\Filtration | ||
subTitle: Framework agnostic data filtering library | ||
|
||
# The left menu bar | ||
menu: | ||
sections: | ||
# versions: | ||
# name: Versions | ||
# items: | ||
# two: | ||
# text: "2.0" | ||
# relativeUrl: | ||
# one: | ||
# text: "1.0" | ||
# relativeUrl: 1_0/ | ||
guide: | ||
name: Getting started | ||
items: | ||
getting_started: | ||
text: Introduction | ||
relativeUrl: | ||
installation: | ||
text: Installation | ||
relativeUrl: installation.html | ||
simple_example: | ||
text: Simple example | ||
relativeUrl: simple_example.html | ||
filters: | ||
text: Built-in filters | ||
relativeUrl: filters.html | ||
syntactic_sugar: | ||
text: Syntactic sugar | ||
relativeUrl: syntactic_sugar.html | ||
advanced: | ||
name: Advanced topics | ||
items: | ||
special_selectors: | ||
text: Special selectors | ||
relativeUrl: special_selectors.html | ||
custom_filter: | ||
text: Custom filters | ||
relativeUrl: custom_filters.html | ||
filter_factory: | ||
text: The filter factory | ||
relativeUrl: filter_factory.html | ||
cookbook: | ||
name: Cookbook | ||
items: | ||
modeling: | ||
text: Filtration for models | ||
relativeUrl: model_filtration.html | ||
outputing: | ||
text: Filtration for output | ||
relativeUrl: output_filtration.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: Custom filters | ||
--- | ||
|
||
# Custom filters | ||
|
||
Hopefully your app is complex enough to require you to build custom filters. Or you will find many uses for this library that you will have to build custom filters. | ||
|
||
Below is the code for a filter that adds a sequence of underscores in front of every item that is passed to it **if** the 'append_underscores' element from the context is true | ||
|
||
```php | ||
namespace MyApp\Filtration\Filter; | ||
|
||
class AppendUnderscores extends Sirius\Filtration\Filter\AbstractFilter { | ||
|
||
function filterSingle($value, $valueIdentifier = null) { | ||
// the context is passed to each filter and represents the entire dataset | ||
// that was sent to be filtered | ||
$no_of_underscores = (int) $this->context['append_underscores'] | ||
return str_repeat('_', $no_of_underscores) . $value; | ||
} | ||
|
||
} | ||
``` | ||
|
||
And it is used like so | ||
|
||
```php | ||
use Sirius\Filtration\Filtrator; | ||
$filtrator = new Filtrator(); | ||
$filtrator->add('content', 'MyApp\Filtration\Filter\AppendUnderscores'); | ||
|
||
$result = $filtrator->filter(array( | ||
'append_underscores' => 10, | ||
'content' => 'Pretty stupid, right?' | ||
)); | ||
|
||
// $result will be | ||
// array( | ||
// 'append_underscores' => 10, | ||
// 'content' => '_________Pretty stupid, right?' | ||
// ) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: The filter factory | ||
--- | ||
|
||
# The filter factory | ||
|
||
Each filtrator object uses individuals filters which are constructed by a `FilterFactory`. The filtrator depends on the filter factory but if you don't provide it, one will be constructed for your | ||
|
||
```php | ||
use Sirius\Filtration\Filtrator; | ||
use Sirius\Filtration\FilterFactory; | ||
|
||
$filterFactory = new FilterFactory(); | ||
$filtrator = new Filtrator($filterFactory); | ||
``` | ||
|
||
You can register your custom filters within the `FilterFactory` like so: | ||
|
||
```php | ||
$filterFactory->register('my_filter', 'MyApp\Filtration\Filter\MyFilter'); | ||
``` | ||
|
||
If you use dependency injection (and you should) you can have a single filter factory for your entire application and register all the filters you need at the beginning of the app. | ||
|
||
If you don't want to do that you can always pass the class to the filtrator: | ||
|
||
```php | ||
$filtrator->add('content', 'MyApp\Filtration\Filter\MyFilter'); | ||
``` | ||
|
||
Also, if your filters are very complex, that is they have dependencies) you need to extend the filter factory. | ||
|
||
```php | ||
namespace MyApp\Filtration; | ||
|
||
class FilterFactory extends Sirius\Filtration\FilterFactory { | ||
|
||
$protected $container = $container; | ||
|
||
function __construct(Container $container) { | ||
$this->container = $container; | ||
} | ||
|
||
function createFilter($callbackOrFilterName, $options = null, $resursive = false) { | ||
$filter = $this->container->get($callbackOrFilterName, [$options, $recursive]); | ||
if (!$filter) { | ||
$filter = parent::createFilter($callbackOrFilterName, $options, $resursive) | ||
} | ||
return $filter; | ||
} | ||
|
||
} | ||
``` | ||
|
||
Or something to that extent. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.