1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Imanghafoori\HeyMan\Switching; |
4
|
|
|
|
5
|
|
|
use Imanghafoori\HeyMan\WatchingStrategies\EloquentModels\EloquentEventsManager; |
6
|
|
|
use Imanghafoori\HeyMan\WatchingStrategies\Events\EventManager; |
7
|
|
|
use Imanghafoori\HeyMan\WatchingStrategies\Routes\RouterEventManager; |
8
|
|
|
use Imanghafoori\HeyMan\WatchingStrategies\Views\ViewEventManager; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Consider. |
12
|
|
|
* |
13
|
|
|
* @method null eventChecks(null|callable $closure = null) |
14
|
|
|
* @method null viewChecks(null|callable $closure = null) |
15
|
|
|
* @method null routeChecks(null|callable $closure = null) |
16
|
|
|
* @method null eloquentChecks(null|callable $closure = null) |
17
|
|
|
* @method null validationChecks(null|callable $closure = null) |
18
|
|
|
*/ |
19
|
|
|
class Consider |
20
|
|
|
{ |
21
|
|
|
private $mode; |
22
|
|
|
|
23
|
15 |
|
public function __construct($mode) |
24
|
|
|
{ |
25
|
15 |
|
$this->mode = $mode; |
26
|
15 |
|
} |
27
|
|
|
|
28
|
15 |
|
public function __call($method, $args) |
29
|
|
|
{ |
30
|
15 |
|
$m = $this->methods(); |
31
|
|
|
|
32
|
15 |
|
return $this->turn($m[$method], ...$args); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
3 |
|
public function allChecks() |
36
|
|
|
{ |
37
|
3 |
|
foreach ($this->methods() as $method => $type) { |
38
|
3 |
|
$this->$method(); |
39
|
|
|
} |
40
|
3 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param $key |
44
|
|
|
* @param callable|null $closure |
45
|
|
|
*/ |
46
|
15 |
|
private function turn($key, callable $closure = null) |
47
|
|
|
{ |
48
|
15 |
|
$key = 'heyman_ignore_'.$key; |
49
|
|
|
|
50
|
15 |
|
$current = config($key); |
51
|
15 |
|
$this->changeMode($key); |
52
|
|
|
|
53
|
15 |
|
if (is_null($closure)) { |
54
|
14 |
|
return; |
55
|
|
|
} |
56
|
1 |
|
$result = $closure(); |
57
|
1 |
|
config()->set($key, $current); |
58
|
|
|
|
59
|
1 |
|
return $result; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param $key |
64
|
|
|
*/ |
65
|
15 |
|
private function changeMode($key) |
66
|
|
|
{ |
67
|
15 |
|
config()->set($key, [ |
68
|
|
|
'turnOff' => true, |
69
|
|
|
'turnOn' => false, |
70
|
15 |
|
][$this->mode]); |
71
|
15 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
15 |
|
private function methods(): array |
77
|
|
|
{ |
78
|
|
|
return [ |
79
|
15 |
|
'eventChecks' => EventManager::class, |
80
|
|
|
'viewChecks' => ViewEventManager::class, |
81
|
|
|
'routeChecks' => RouterEventManager::class, |
82
|
|
|
'eloquentChecks' => EloquentEventsManager::class, |
83
|
|
|
'validationChecks' => 'validation', |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|