forked from beluga-php/docker-php-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeSpecNormalizer.php
More file actions
103 lines (93 loc) · 3.62 KB
/
Copy pathNodeSpecNormalizer.php
File metadata and controls
103 lines (93 loc) · 3.62 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
declare(strict_types=1);
namespace Docker\API\Normalizer;
use Docker\API\Runtime\Normalizer\CheckArray;
use Jane\Component\JsonSchemaRuntime\Reference;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class NodeSpecNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
{
use CheckArray;
use DenormalizerAwareTrait;
use NormalizerAwareTrait;
/**
* @return bool
*/
public function supportsDenormalization($data, $type, $format = null)
{
return 'Docker\\API\\Model\\NodeSpec' === $type;
}
public function supportsNormalization($data, $format = null)
{
return \is_object($data) && 'Docker\\API\\Model\\NodeSpec' === $data::class;
}
/**
* @return mixed
*/
public function denormalize($data, $class, $format = null, array $context = [])
{
if (isset($data['$ref'])) {
return new Reference($data['$ref'], $context['document-origin']);
}
if (isset($data['$recursiveRef'])) {
return new Reference($data['$recursiveRef'], $context['document-origin']);
}
$object = new \Docker\API\Model\NodeSpec();
if (null === $data || false === \is_array($data)) {
return $object;
}
if (\array_key_exists('Name', $data) && null !== $data['Name']) {
$object->setName($data['Name']);
} elseif (\array_key_exists('Name', $data) && null === $data['Name']) {
$object->setName(null);
}
if (\array_key_exists('Labels', $data) && null !== $data['Labels']) {
$values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
foreach ($data['Labels'] as $key => $value) {
$values[$key] = $value;
}
$object->setLabels($values);
} elseif (\array_key_exists('Labels', $data) && null === $data['Labels']) {
$object->setLabels(null);
}
if (\array_key_exists('Role', $data) && null !== $data['Role']) {
$object->setRole($data['Role']);
} elseif (\array_key_exists('Role', $data) && null === $data['Role']) {
$object->setRole(null);
}
if (\array_key_exists('Availability', $data) && null !== $data['Availability']) {
$object->setAvailability($data['Availability']);
} elseif (\array_key_exists('Availability', $data) && null === $data['Availability']) {
$object->setAvailability(null);
}
return $object;
}
/**
* @return array|string|int|float|bool|\ArrayObject|null
*/
public function normalize($object, $format = null, array $context = [])
{
$data = [];
if (null !== $object->getName()) {
$data['Name'] = $object->getName();
}
if (null !== $object->getLabels()) {
$values = [];
foreach ($object->getLabels() as $key => $value) {
$values[$key] = $value;
}
$data['Labels'] = $values;
}
if (null !== $object->getRole()) {
$data['Role'] = $object->getRole();
}
if (null !== $object->getAvailability()) {
$data['Availability'] = $object->getAvailability();
}
return $data;
}
}