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