Skip to content

Commit

Permalink
By default do not run methods that have empty value
Browse files Browse the repository at this point in the history
  • Loading branch information
mirovit committed Oct 11, 2016
1 parent 300b030 commit 1063d86
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ abstract class Filter
*/
protected $builder;

/**
* Specify method names, which should be run
* even when the value is with length of 0.
*
* @var array
*/
protected $alwaysRun = [];

/**
* @param Request $request
*/
Expand All @@ -46,6 +54,10 @@ public function apply(Builder $builder)
continue;
}

if(! $this->shouldRunMethod($name, $value)) {
continue;
}

call_user_func([$this, $name], $value);
}

Expand Down Expand Up @@ -85,4 +97,14 @@ public function sort(array $sort)

return $builder;
}

/**
* @param $method
* @param $value
* @return bool
*/
protected function shouldRunMethod($method, $value)
{
return in_array($method, $this->alwaysRun) || strlen($value) > 0;
}
}

0 comments on commit 1063d86

Please sign in to comment.