IsCustomizable::withCustomEagerMatchingCallback()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Staudenmeir\EloquentHasManyDeep\Eloquent\Relations\Traits;
4
5
trait IsCustomizable
6
{
7
    /**
8
     * The custom callbacks to run at the end of the get() method.
9
     *
10
     * @var callable[]
11
     */
12
    protected array $postGetCallbacks = [];
13
14
    /**
15
     * The custom through key callback for an eager load of the relation.
16
     *
17
     * @var callable
18
     */
19
    protected $customThroughKeyCallback = null;
20
21
    /**
22
     * The custom constraints callback for an eager load of the relation.
23
     *
24
     * @var callable
25
     */
26
    protected $customEagerConstraintsCallback = null;
27
28
    /**
29
     * The custom matching callbacks for the eagerly loaded results.
30
     *
31
     * @var callable[]
32
     */
33
    protected array $customEagerMatchingCallbacks = [];
34
35
    /**
36
     * Set custom callbacks to run at the end of the get() method.
37
     *
38
     * @param callable[] $callbacks
39
     * @return $this
40
     */
41
    public function withPostGetCallbacks(array $callbacks): static
42
    {
43
        $this->postGetCallbacks = array_merge($this->postGetCallbacks, $callbacks);
44
45
        return $this;
46
    }
47
48
    /**
49
     * Set the custom through key callback for an eager load of the relation.
50
     *
51
     * @param callable $callback
52
     * @return $this
53
     */
54
    public function withCustomThroughKeyCallback(callable $callback): static
55
    {
56
        $this->customThroughKeyCallback = $callback;
57
58
        return $this;
59
    }
60
61
    /**
62
     * Set the custom constraints callback for an eager load of the relation.
63
     *
64
     * @param callable $callback
65
     * @return $this
66
     */
67
    public function withCustomEagerConstraintsCallback(callable $callback): static
68
    {
69
        $this->customEagerConstraintsCallback = $callback;
70
71
        return $this;
72
    }
73
74
    /**
75
     * Set a custom matching callback for the eagerly loaded results.
76
     *
77
     * @param callable $callback
78
     * @return $this
79
     */
80
    public function withCustomEagerMatchingCallback(callable $callback): static
81
    {
82
        $this->customEagerMatchingCallbacks[] = $callback;
83
84
        return $this;
85
    }
86
}
87