Skip to content

Commit

Permalink
Merge pull request #93 from K-Phoen/improve-doc
Browse files Browse the repository at this point in the history
Improve doc
  • Loading branch information
K-Phoen authored Oct 12, 2017
2 parents cdd6cff + 71f7f6f commit 83109a0
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 18 deletions.
8 changes: 6 additions & 2 deletions doc/cookbooks/doctrine_orm.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ $playersQueryBuilder = $entityManager

$rule = '"ROLE_ADMIN" IN group.roles';

var_dump($rulerz->filter($playersQueryBuilder, $rule));
var_dump(
iterator_to_array($rulerz->filter($playersQueryBuilder, $rule))
);
```

It's important to notice that `group` is not an ordinary attribute: it's another
Expand All @@ -104,7 +106,9 @@ $playersQueryBuilder = $entityManager

$rule = '"ROLE_ADMIN" IN g.roles';

var_dump($rulerz->filter($playersQueryBuilder, $rule));
var_dump(
iterator_to_array($rulerz->filter($playersQueryBuilder, $rule))
);
```

This time, RulerZ is smart enough to understand that `g` might be a joined
Expand Down
4 changes: 3 additions & 1 deletion doc/cookbooks/elastic_elasticsearch_php.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ $executionContext = [
'type' => 'type_name',
];

var_dump($rulerz->filter($client, $rule, $parameters, $executionContext));
var_dump(
iterator_to_array($rulerz->filter($client, $rule, $parameters, $executionContext))
);
```

**N.B**: you'll notice an unusual variable named `$executionContext`. It
Expand Down
6 changes: 4 additions & 2 deletions doc/cookbooks/eloquent_orm.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ $parameters = [
'gender' => 'M',
];

var_dump($rulerz->filter($queryBuilder, $rule, $parameters));
var_dump(
iterator_to_array($rulerz->filter($queryBuilder, $rule, $parameters))
);
```

## That was it!

[Return to the index to explore the other possibilities of the library](../index.md)
[Return to the index to explore the other possibilities of the library](../index.md)
6 changes: 4 additions & 2 deletions doc/cookbooks/pomm.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ $parameters = [
'gender' => 'M',
];

var_dump($rulerz->filter($playerModel, $rule, $parameters));
var_dump(
iterator_to_array($rulerz->filter($playerModel, $rule, $parameters))
);
```

## That was it!

[Return to the index to explore the other possibilities of the library](../index.md)
[Return to the index to explore the other possibilities of the library](../index.md)
4 changes: 3 additions & 1 deletion doc/cookbooks/ruflin_elastica.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ $parameters = [
'gender' => 'M',
];

var_dump($rulerz->filter($search, $rule, $parameters));
var_dump(
iterator_to_array($rulerz->filter($search, $rule, $parameters))
);
```

## That was it!
Expand Down
4 changes: 3 additions & 1 deletion doc/cookbooks/solarium.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ $parameters = [
'gender' => 'M',
];

var_dump($rulerz->filter($client, $rule, $parameters));
var_dump(
iterator_to_array($rulerz->filter($client, $rule, $parameters))
);
```

## That was it!
Expand Down
13 changes: 11 additions & 2 deletions doc/filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ This guide will show you how to filter any kind of target using a simple languag

Here is a summary of what you will have to do:

* [instantiate the RulerZ engine](writing_rules.md#step-1-instantiate-the-rulerz-engine) ;
* [instantiate the RulerZ engine](writing_rules.md#step-1-instantiate-the-rulerz-engine)
and be sure to **include an instance of `\RulerZ\Target\Native\Native` to the
compilation targets** ;
* [write a rule](writing_rules.md#step-2-write-a-rule) ;
* [filter your target](#filter-your-target).

Expand All @@ -21,6 +23,9 @@ $users = [
];
```

**Note:** RulerZ will work the same way, whether you want to filter a collection
of arrays or a collection of objects.

## Filter your target

Let's say that we want to retrieve the female players having at least 30 points.
Expand All @@ -44,7 +49,11 @@ Once the rule is written and the parameters are defined, only the easiest part
remains: filtering the target.

```php
var_dump($rulerz->filter($players, $rule, $parameters)); // the parameters can be omitted if empty
var_dump(
iterator_to_array(
$rulerz->filter($players, $rule, $parameters) // the parameters can be omitted if empty
)
);

// will return:
/*
Expand Down
1 change: 1 addition & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ composer require 'kphoen/rulerz'

## Cookbooks

* [Using native PHP arrays or objects](filter.md)
* [Using Doctrine ORM](cookbooks/doctrine_orm.md)
* [Using Pomm](cookbooks/pomm.md)
* [Using Elasticsearch and ruflin/Elastica](cookbooks/ruflin_elastica.md)
Expand Down
1 change: 1 addition & 0 deletions src/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function visit(Visitor\Element $element, &$handle = null, $eldnah = null)
switch ($child->getId()) {
case '#attribute_access':
$name->attribute($_child);

break;
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/features/bootstrap/BaseContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public function __construct()
$this->initialize();
}

/**
* @BeforeSuite
*/
public static function prepare(BeforeSuiteScope $scope)
{
echo 'Current suite: '.$scope->getSuite()->getName();
}
/**
* @BeforeSuite
*/
public static function prepare(BeforeSuiteScope $scope)
{
echo 'Current suite: '.$scope->getSuite()->getName();
}

/**
* Will be called right after the construction of the context, useful to
Expand Down

0 comments on commit 83109a0

Please sign in to comment.