text changes to registration mail content
[namibia] / module / Workspace / src / Workspace / UseCase / Requirement.php
1 <?php
2 namespace Workspace\UseCase;
3
4
5
6 /**
7  * Basic input requirement handler used for service contracts.
8  * @author andre.fourie
9  */
10 class Requirement
11 {
12
13         /**
14          * @var \Repo\Field\Collector
15          */
16         protected $collector;
17         /**
18          * @var array
19          */
20         protected $requiredFields = array();
21         /**
22          * @var array
23          */
24         protected $inputFields = array();
25
26
27         /**
28          * Initialize requirement.
29          * @return \Workspace\UseCase\Requirement
30          */
31         public function __construct()
32         {
33                 $this->collector = new \Repo\Field\Collector();
34         }
35
36         /**
37          * Add required input(s).
38          * @param string|array $input
39          * @return \Workspace\UseCase\Requirement
40          */
41         public function addRequiredInput($input)
42         {
43                 $newStack = $this->collector->collect($input);
44                 foreach ($newStack as $group => $fieldSet)
45                 {
46                         isset($this->requiredFields[$group])
47                                 || $this->requiredFields[$group] = array();
48                         isset($this->inputFields[$group])
49                                 || $this->inputFields[$group] = array();
50                         foreach ($fieldSet as $field => $validation)
51                         {
52                                 $this->requiredFields[$group][$field] = $field;
53                         }
54                         $this->inputFields[$group] = array_merge($this->inputFields[$group], $fieldSet);
55                 }
56                 return $this;
57         }
58
59         /**
60          * Add optional input(s).
61          * @param string|array $input
62          * @return \Workspace\UseCase\Requirement
63          */
64         public function addOptionalInput($input)
65         {
66                 $newStack = $this->collector->collect($input);
67                 foreach ($newStack as $group => $fieldSet)
68                 {
69                         isset($this->inputFields[$group])
70                                 || $this->inputFields[$group] = array();
71                         $this->inputFields[$group] = array_merge($this->inputFields[$group], $fieldSet);
72                 }
73                 return $this;
74         }
75
76         /**
77          * Retrieve shortlist of required inputs.
78          * @return array
79          */
80         public function getRequirements()
81         {
82                 return $this->requiredFields;
83         }
84
85         /**
86          * Retrieve list of all inputs.
87          * @return array
88          */
89         public function getInputs()
90         {
91                 return $this->inputFields;
92         }
93
94 }