-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallbackPolicy.php
75 lines (67 loc) · 1.4 KB
/
CallbackPolicy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php declare(strict_types=1);
/**
* Part of Windwalker project.
*
* @copyright Copyright (C) 2019 LYRASOFT.
* @license GNU General Public License version 2 or later.
*/
namespace Windwalker\Authorisation;
/**
* The CallbackPolicy class.
*
* @since 3.0
*/
class CallbackPolicy implements PolicyInterface
{
/**
* Property handler.
*
* @var callable
*/
protected $handler;
/**
* CallbackPolicy constructor.
*
* @param callable $handler
*/
public function __construct($handler)
{
$this->setHandler($handler);
}
/**
* authorise
*
* @param mixed $user
* @param mixed $data
*
* @return boolean
*/
public function authorise($user, $data = null)
{
return call_user_func_array($this->handler, func_get_args());
}
/**
* Method to get property Handler
*
* @return callable
*/
public function getHandler()
{
return $this->handler;
}
/**
* Method to set property handler
*
* @param callable $handler
*
* @return static Return self to support chaining.
*/
public function setHandler($handler)
{
if (!is_callable($handler)) {
throw new \InvalidArgumentException('Handler should be a valid callback');
}
$this->handler = $handler;
return $this;
}
}