Completed
Push — master ( 0df1f8...958d5f )
by Sébastien
07:01
created

GateCallback::check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Sebdesign\SM\Callback;
4
5
use SM\Callback\Callback;
6
use Illuminate\Contracts\Auth\Access\Gate;
7
8
class GateCallback extends Callback
9
{
10
    /**
11
     * @var \Illuminate\Contracts\Auth\Access\Gate
12
     */
13
    protected $gate;
14
15
    /**
16
     * @param array                                  $specs Specification for the callback to be called
17
     * @param \Illuminate\Contracts\Auth\Access\Gate $gate  The service container that will be used to resolve the callable
18
     */
19
    public function __construct(array $specs, Gate $gate)
20
    {
21
        if (! isset($specs['args'])) {
22
            $specs['args'] = ['object'];
23
        }
24
25
        parent::__construct($specs, [$this, 'check']);
26
27
        $this->gate = $gate;
28
    }
29
30
    /**
31
     * Check if the abilities are allowed against the gate.
32
     *
33
     * @return bool
34
     */
35
    public function check()
36
    {
37
        return $this->gate->check($this->specs['can'], func_get_args());
38
    }
39
}
40