Passed
Push β€” master ( bd9b88...11a7f9 )
by Fu
08:59 queued 03:53
created

RequestCriteria::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: guoliang
5
 * Date: 2019/3/11
6
 * Time: 上午10:11
7
 */
8
9
namespace Modules\Core\Criteria;
10
11
12
use Illuminate\Http\Request;
13
use Modules\Core\Traits\Criteria\{
14
    ParseFilterTrait,
15
    ParseOrderByTrait,
16
    ParseSearchableTrait,
17
    ParseWithTrait
18
};
19
use Prettus\Repository\Contracts\{
20
    CriteriaInterface,
21
    RepositoryInterface
22
};
23
24
class RequestCriteria implements CriteriaInterface
25
{
26
    /** @var \Illuminate\Http\Request $request */
27
    protected $request;
28
    /** @var \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder $model */
29
    protected $model;
30
    /** @var \Prettus\Repository\Contracts\RepositoryInterface $repository */
31
    protected $repository;
32
    protected $search;
33
    protected $searchData;
34
    protected $searchFields;
35
    protected $isFirstField = true;
36
    protected $modelForceAndWhere;
37
    protected $fieldsSearchable;
38
    protected $fields;
39
    protected $filter;
40
    protected $orderBy;
41
    protected $sortedBy;
42
    protected $with;
43
    protected $searchJoin;
44
    protected $acceptedConditions;
45
    protected $originalFields;
46
47
    use ParseSearchableTrait;
48
    use ParseOrderByTrait;
49
    use ParseFilterTrait;
50
    use ParseWithTrait;
51
52
    public function __construct(Request $request)
53
    {
54
        $this->request = $request;
55
    }
56
57
    /**
58
     * @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Query\Builder $model
59
     * @param \Prettus\Repository\Contracts\RepositoryInterface $repository
60
     * @return mixed
61
     * @throws \Exception
62
     */
63
    public function apply($model, RepositoryInterface $repository)
64
    {
65
        $this->model = $model;
66
        $this->repository = $repository;
67
68
        $this->parseSearchable();
69
        $this->parseOrderBy();
70
        $this->parseFilter();
71
        $this->parseWith();
72
73
        return $this->model;
74
    }
75
}
76