1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the WPSymfonyForm plugin. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2015-2016 LIN3S <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LIN3S\WPSymfonyForm\Wrapper; |
13
|
|
|
|
14
|
|
|
use LIN3S\WPSymfonyForm\Action\Action; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* FormWrapper class. |
18
|
|
|
* |
19
|
|
|
* @author Gorka Laucirica <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class FormWrapper |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The fully qualified class name of form. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $formClass; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The name of the form. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $name; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Collection of actions. |
39
|
|
|
* |
40
|
|
|
* @var Action[] |
41
|
|
|
*/ |
42
|
|
|
protected $successActions; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Generates a wrapper for a given form. |
46
|
|
|
* |
47
|
|
|
* @param string $name The name of form |
48
|
|
|
* @param string $formClass Fqcn of form |
49
|
|
|
* @param Action[] $successActions Collection of actions |
50
|
|
|
*/ |
51
|
|
|
public function __construct($name, $formClass, array $successActions = []) |
52
|
|
|
{ |
53
|
|
|
$this->formClass = $formClass; |
54
|
|
|
$this->name = $name; |
55
|
|
|
foreach ($successActions as $action) { |
56
|
|
|
if (!$action instanceof Action) { |
57
|
|
|
throw new \InvalidArgumentException( |
58
|
|
|
'All actions passed to the FormWrapper must be an instance of Action' |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
$this->successActions = $successActions; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Gets the fully qualified class name of the form. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getForm() |
71
|
|
|
{ |
72
|
|
|
return $this->formClass; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Gets name of the form. |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function getName() |
81
|
|
|
{ |
82
|
|
|
return $this->name; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns registered actions to be called in form success. |
87
|
|
|
* |
88
|
|
|
* @return Action[] |
89
|
|
|
*/ |
90
|
|
|
public function getSuccessActions() |
91
|
|
|
{ |
92
|
|
|
return $this->successActions; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|