| 1 | <?php |
||
| 13 | abstract class BaseScope implements ScopeInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var Request|null |
||
| 17 | */ |
||
| 18 | protected $request; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string|null |
||
| 22 | */ |
||
| 23 | protected $primary; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string|null |
||
| 27 | */ |
||
| 28 | protected $secondary; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * BaseScope constructor. |
||
| 32 | * |
||
| 33 | * @param null $request |
||
| 34 | * @param null $primary |
||
| 35 | * @param null $secondary |
||
| 36 | */ |
||
| 37 | public function __construct($request = null, $primary = null, $secondary = null) |
||
| 38 | { |
||
| 39 | $this->request = $request !== null ? $request : app(Request::class); |
||
| 40 | $this->primary = $primary !== null ? $primary : config('queryScope.primarySeparator'); |
||
| 41 | $this->secondary = $this->secondary !== null ? $secondary : config('queryScope.secondarySeparator'); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * return params has array. |
||
| 46 | * |
||
| 47 | * @param string|array $content |
||
| 48 | * |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | public function hasArray($content = []) |
||
| 52 | { |
||
| 53 | if (is_array($content)) { |
||
| 54 | return $content; |
||
| 55 | } |
||
| 56 | |||
| 57 | if (is_string($content)) { |
||
| 58 | return str_contains($content, $this->primary) ? |
||
| 59 | explode($this->primary, $content) : |
||
| 60 | [$content]; |
||
| 61 | } |
||
| 62 | |||
| 63 | return []; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param Builder $builder |
||
| 68 | * @param Model $model |
||
| 69 | * |
||
| 70 | * @return Builder |
||
| 71 | */ |
||
| 72 | abstract public function apply(Builder $builder, Model $model); |
||
| 73 | } |
||
| 74 |