Completed
Push — master ( a24de7...5bce41 )
by Kévin
03:41
created

Eloquent::createVisitor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace RulerZ\Target\Eloquent;
4
5
use RulerZ\Compiler\Context;
6
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
7
use Illuminate\Database\Query\Builder as QueryBuilder;
8
9
use RulerZ\Target\AbstractSqlTarget;
10
11
class Eloquent extends AbstractSqlTarget
12
{
13
    /**
14
     * Allow eloquent builder as query.
15
     *
16
     * @var bool
17
     */
18
    protected $allowEloquentBuilderAsQuery = false;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param bool            $allowEloquentBuilderAsQuery Whether to allow the execution target to be eloquent builder instead of query builder.
24
     */
25
    public function __construct($allowEloquentBuilderAsQuery = false)
26
    {
27
        parent::__construct();
28
29
        $this->allowEloquentBuilderAsQuery = (bool) $allowEloquentBuilderAsQuery;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function supports($target, $mode)
36
    {
37
        return $target instanceof QueryBuilder || $target instanceof EloquentBuilder;
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    protected function getExecutorTraits()
44
    {
45
        return [
46
            '\RulerZ\Executor\Eloquent\FilterTrait',
47
            '\RulerZ\Executor\Polyfill\FilterBasedSatisfaction',
48
        ];
49
    }
50
51
    /**
52
     * @inheritDoc
53
     */
54
    protected function createVisitor(Context $context)
55
    {
56
        return new EloquentVisitor($context, $this->getOperators(), $this->allowStarOperator, $this->allowEloquentBuilderAsQuery);
57
    }
58
}
59