Skip to content

Commit

Permalink
ready
Browse files Browse the repository at this point in the history
  • Loading branch information
gcphost committed Aug 1, 2016
1 parent 3f02087 commit cd17ef2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Askedio\LaravelValidatorFilter\FilterServiceProvider::class
# Examples

You can use any function that has been defined and accepts the value as the parameter.
~~~
```php
$validator = app('validator')->make([
'string' => 'Hello ' . PHP_EOL . ' World',
], [
Expand All @@ -31,10 +31,10 @@ $validator = app('validator')->make([
$validator->passes();

dd($validator->getData());
~~~
```

You can define the paramaters in line with, `()` = `[]` and `,` = `;`.
~~~
```php
$validator = app('validator')->make([
'string' => 'Hello <br> World<p></p>',
], [
Expand All @@ -44,10 +44,10 @@ $validator = app('validator')->make([
$validator->passes();

dd($validator->getData());
~~~
```

You can also define your own custom filter.
~~~
```php
app('filter')->register('plusOne', function ($value) {
return $value+1;
});
Expand All @@ -61,4 +61,4 @@ $validator = app('validator')->make([
$validator->passes();

dd($validator->getData());
~~~
```
10 changes: 5 additions & 5 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Filter

protected $validator;

protected $functional;
protected $functionString;

protected $filters = [];

Expand Down Expand Up @@ -61,16 +61,16 @@ protected function process()

protected function stringHasAFunction($param)
{
preg_match('/(.*)\[(.*)\]/s', $param, $this->functional);
preg_match('/(.*)\[(.*)\]/s', $param, $this->functionString);

return count($this->functional) == 3 && is_callable($this->functional[1]);
return count($this->functionString) == 3 && is_callable($this->functionString[1]);
}

private function callFunctionFromString($value)
{
return call_user_func_array($this->functional[1], array_map(function ($string) use ($value) {
return call_user_func_array($this->functionString[1], array_map(function ($string) use ($value) {
return strtr($string, ['{$value}' => $value]);
}, explode(';', $this->functional[2])));
}, explode(';', $this->functionString[2])));
}

private function replace()
Expand Down

0 comments on commit cd17ef2

Please sign in to comment.