/
Input.php
70 lines (58 loc) · 1.64 KB
/
Input.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Concrete\Core\Command\Task\Input;
use Concrete\Core\Command\Task\Input\FieldInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizableInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
defined('C5_EXECUTE') or die("Access Denied.");
/**
* Responsible for presenting all loaded Concrete\Core\Command\Task\Input\FieldInterface fields to the actual
* task system.
*
* @package Concrete\Core\Command\Task\Input
*/
class Input implements InputInterface, DenormalizableInterface
{
/**
* @var FieldInterface[]
*/
protected $fields = [];
public function addField(FieldInterface $field)
{
$this->fields[] = $field;
}
public function getField(string $key): ?FieldInterface
{
foreach($this->fields as $field) {
if ($field->getKey() == $key) {
return $field;
}
}
return null;
}
public function hasField(string $key): bool
{
foreach($this->fields as $field) {
if ($field->getKey() == $key) {
return true;
}
}
return false;
}
public function getFields()
{
return $this->fields;
}
public function jsonSerialize()
{
return [
'fields' => $this->fields,
];
}
public function denormalize(DenormalizerInterface $denormalizer, $data, string $format = null, array $context = [])
{
foreach ($data['fields'] as $field) {
$field = $denormalizer->denormalize($field, Field::class, 'json', $context);
$this->addField($field);
}
}
}