forked from spmartin/docker-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortConfigNormalizer.php
More file actions
66 lines (56 loc) · 1.97 KB
/
Copy pathPortConfigNormalizer.php
File metadata and controls
66 lines (56 loc) · 1.97 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
<?php
namespace Docker\API\Normalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer;
class PortConfigNormalizer extends SerializerAwareNormalizer implements DenormalizerInterface, NormalizerInterface
{
public function supportsDenormalization($data, $type, $format = null)
{
if ($type !== 'Docker\\API\\Model\\PortConfig') {
return false;
}
return true;
}
public function supportsNormalization($data, $format = null)
{
if ($data instanceof \Docker\API\Model\PortConfig) {
return true;
}
return false;
}
public function denormalize($data, $class, $format = null, array $context = [])
{
$object = new \Docker\API\Model\PortConfig();
if (property_exists($data, 'Name')) {
$object->setName($data->{'Name'});
}
if (property_exists($data, 'Protocol')) {
$object->setProtocol($data->{'Protocol'});
}
if (property_exists($data, 'TargetPort')) {
$object->setTargetPort($data->{'TargetPort'});
}
if (property_exists($data, 'PublishedPort')) {
$object->setPublishedPort($data->{'PublishedPort'});
}
return $object;
}
public function normalize($object, $format = null, array $context = [])
{
$data = new \stdClass();
if (null !== $object->getName()) {
$data->{'Name'} = $object->getName();
}
if (null !== $object->getProtocol()) {
$data->{'Protocol'} = $object->getProtocol();
}
if (null !== $object->getTargetPort()) {
$data->{'TargetPort'} = $object->getTargetPort();
}
if (null !== $object->getPublishedPort()) {
$data->{'PublishedPort'} = $object->getPublishedPort();
}
return $data;
}
}