1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\LaravelResourceEndpoints; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use Spatie\LaravelResourceEndpoints\EndpointTypes\ActionEndpointType; |
7
|
|
|
use Spatie\LaravelResourceEndpoints\EndpointTypes\ControllerEndpointType; |
8
|
|
|
use Spatie\LaravelResourceEndpoints\EndpointTypes\InvokableControllerEndpointType; |
9
|
|
|
|
10
|
|
|
class EndpointsGroup |
11
|
|
|
{ |
12
|
|
|
/** @var \Illuminate\Support\Collection */ |
13
|
|
|
private $endpointTypes; |
14
|
|
|
|
15
|
|
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
$this->endpointTypes = new Collection(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function controller(string $controller): ControllerEndpointType |
21
|
|
|
{ |
22
|
|
|
if (method_exists($controller, '__invoke')) { |
23
|
|
|
return $this->invokableController($controller); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$controllerEndpointType = ControllerEndpointType::make($controller); |
27
|
|
|
|
28
|
|
|
$this->endpointTypes[] = $controllerEndpointType; |
29
|
|
|
|
30
|
|
|
return $controllerEndpointType; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function invokableController(string $controller): InvokableControllerEndpointType |
34
|
|
|
{ |
35
|
|
|
$invokableControllerEndpointType = InvokableControllerEndpointType::make($controller); |
36
|
|
|
|
37
|
|
|
$this->endpointTypes[] = $invokableControllerEndpointType; |
38
|
|
|
|
39
|
|
|
return $invokableControllerEndpointType; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function action(array $action): ActionEndpointType |
43
|
|
|
{ |
44
|
|
|
$actionEndpointType = ActionEndpointType::make($action); |
45
|
|
|
|
46
|
|
|
$this->endpointTypes[] = $actionEndpointType; |
47
|
|
|
|
48
|
|
|
return $actionEndpointType; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function endpointsGroup(EndpointsGroup $endpointsGroup) |
52
|
|
|
{ |
53
|
|
|
$this->endpointTypes = $this->endpointTypes->merge( |
54
|
|
|
$endpointsGroup->getEndpointTypes() |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getEndpointTypes(): Collection |
59
|
|
|
{ |
60
|
|
|
return $this->endpointTypes; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|