Skip to content

Commit a5e46fd

Browse files
committed
new Actions
1 parent 145b1e2 commit a5e46fd

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/Makes/Stubs/Init/Contracts/Action.stub

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,25 @@
33
namespace App\Contracts;
44

55
use App\Interfaces\IAction;
6+
use App\Models\User;
67

78
abstract class Action implements IAction
89
{
9-
# Блокировка инстанцирования
10-
final private function __construct() {}
10+
/**
11+
* Пользователь, который вызвал этот Action
12+
*/
13+
protected ?User $user;
14+
15+
final public function __construct()
16+
{
17+
$this->user = $this->authorize();
18+
}
19+
20+
/**
21+
* Проверяет, есть ли у пользователя доступ к этому Action
22+
*/
23+
public function authorize(): ?User
24+
{
25+
return null;
26+
}
1127
}

src/Makes/Stubs/Init/Interfaces/IAction.stub

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace App\Interfaces;
44

5+
use App\Models\User;
6+
57
interface IAction
68
{
7-
9+
public function authorize(): ?User;
810
}

src/Makes/Stubs/make-action.stub

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
namespace {{ namespace }};
44

55
use {{ rootNamespace }}Contracts\Action;
6+
use App\Models\User;
67

78
/**
89
*
910
*/
1011
final class {{ class }} extends Action
1112
{
13+
public function authorize(): ?User
14+
{
15+
//
16+
}
17+
1218
/**
1319
*
1420
*/
15-
public static function run() : array
21+
public function run() : array
1622
{
1723
return [];
1824
}

0 commit comments

Comments
 (0)