|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Http\Action; |
|
6
|
|
|
|
|
7
|
|
|
// framework |
|
8
|
|
|
use DarkMatter\Action\HtmlAction; |
|
9
|
|
|
use DarkMatter\Http\Response; |
|
10
|
|
|
|
|
11
|
|
|
// application |
|
12
|
|
|
use App\Domain\HomeDomainPayload; |
|
13
|
|
|
use App\Http\PayloadResponder; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class HomeActionPayload |
|
17
|
|
|
* |
|
18
|
|
|
* This is an example of a HtmlAction. In every HtmlAction you have access to the HtmlResponder. |
|
19
|
|
|
* |
|
20
|
|
|
* @package DarkMatterApp\Actions |
|
21
|
|
|
*/ |
|
22
|
|
|
class HomeActionPayload extends HtmlAction |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Every Action needs to have a "__invoke" methods which is automatically executed by the application. |
|
26
|
|
|
* 1. The Action asks data from the Domain, which returns a Payload with the Payload Status |
|
27
|
|
|
* 2. This methods needs to return the response with the Payload which will than be send to the client. |
|
28
|
|
|
* 3. The Responder sets the Respomse |
|
29
|
|
|
* |
|
30
|
|
|
* https://github.com/pmjones/adr-example/blob/master/src/Web/Blog/Read/BlogReadAction.php |
|
31
|
|
|
* PAYLOAD = domain result // DOMAIN sets the payload and STATUS |
|
32
|
|
|
* retuns responder to // return $this->responder->__invoke($request, $payload); |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $arguments Possible arguments from the URL. |
|
35
|
|
|
* @return Response |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __invoke(array $arguments = []) : Response |
|
38
|
|
|
{ |
|
39
|
|
|
// 0 get argument from request | route config: '/payloadtest/[{id:\d+}]', |
|
40
|
|
|
// 1 new domain with route args |
|
41
|
|
|
// 2 get data from domain with route args |
|
42
|
|
|
// 3 call responder with payload from domain |
|
43
|
|
|
|
|
44
|
|
|
if (!isset($arguments['id'])) { |
|
45
|
|
|
$arguments['id'] = 42; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// |
|
49
|
|
|
$domain = new HomeDomainPayload($arguments); |
|
50
|
|
|
$payload = $domain->getWelcomePayload(); |
|
51
|
|
|
|
|
52
|
|
|
// html responder |
|
53
|
|
|
// $responder = $this->responder->payload($payload); |
|
54
|
|
|
|
|
55
|
|
|
// Set Payload responder |
|
56
|
|
|
$this->setResponder(new PayloadResponder($this->config)); |
|
57
|
|
|
$responder = $this->responder->__invoke($payload); |
|
58
|
|
|
|
|
59
|
|
|
return $responder; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|