|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WebTheory\Saveyour\Controller\Abstracts; |
|
4
|
|
|
|
|
5
|
|
|
use ArrayIterator; |
|
6
|
|
|
use IteratorAggregate; |
|
7
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
8
|
|
|
use Traversable; |
|
9
|
|
|
use WebTheory\Saveyour\Contracts\Auth\FormShieldInterface; |
|
10
|
|
|
use WebTheory\Saveyour\Contracts\Controller\FormFieldControllerInterface; |
|
11
|
|
|
use WebTheory\Saveyour\Contracts\Controller\FormInterface; |
|
12
|
|
|
use WebTheory\Saveyour\Contracts\Controller\FormSubmissionManagerInterface; |
|
13
|
|
|
use WebTheory\Saveyour\Contracts\Processor\FormDataProcessorInterface; |
|
14
|
|
|
use WebTheory\Saveyour\Contracts\Report\ProcessedFormReportInterface; |
|
15
|
|
|
use WebTheory\Saveyour\Controller\FormSubmissionManager; |
|
16
|
|
|
|
|
17
|
|
|
abstract class AbstractForm implements FormInterface, IteratorAggregate |
|
18
|
|
|
{ |
|
19
|
|
|
public function data(ServerRequestInterface $request): array |
|
20
|
|
|
{ |
|
21
|
|
|
return [ |
|
22
|
|
|
'method' => $this->method(), |
|
23
|
|
|
'action' => $this->action(), |
|
24
|
|
|
'checks' => $this->checks(), |
|
25
|
|
|
'fields' => $this->fields(), |
|
26
|
|
|
]; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function process(ServerRequestInterface $request): ProcessedFormReportInterface |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->manager()->process($request); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getIterator(): Traversable |
|
35
|
|
|
{ |
|
36
|
|
|
return new ArrayIterator($this->fields()); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function html(ServerRequestInterface $request): ?string |
|
40
|
|
|
{ |
|
41
|
|
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function manager(): FormSubmissionManagerInterface |
|
45
|
|
|
{ |
|
46
|
|
|
return new FormSubmissionManager( |
|
47
|
|
|
$this->controllers(), |
|
48
|
|
|
$this->processors(), |
|
49
|
|
|
$this->shield() |
|
|
|
|
|
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function shield(): ?FormShieldInterface |
|
54
|
|
|
{ |
|
55
|
|
|
return null; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return array<string, FormFieldControllerInterface> |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function controllers(): array |
|
62
|
|
|
{ |
|
63
|
|
|
return []; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return array<string,FormDataProcessorInterface> |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function processors(): array |
|
70
|
|
|
{ |
|
71
|
|
|
return []; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
abstract protected function action(): string; |
|
75
|
|
|
|
|
76
|
|
|
abstract protected function method(): string; |
|
77
|
|
|
|
|
78
|
|
|
abstract protected function checks(): string; |
|
79
|
|
|
|
|
80
|
|
|
abstract protected function fields(): iterable; |
|
81
|
|
|
} |
|
82
|
|
|
|