address: POST an address

This commit is contained in:
nobohan
2021-05-28 10:14:54 +02:00
parent 057db09847
commit 165012b302
4 changed files with 45 additions and 9 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace Chill\MainBundle\Serializer\Normalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Chill\MainBundle\Doctrine\Model\Point;
class PointNormalizer implements DenormalizerInterface
{
public function supportsDenormalization($data, string $type, string $format = null) : bool
{
return $type === Point::class;
}
public function denormalize($data, string $type, string $format = null, array $context = [])
{
if (!is_array($data)) {
throw new InvalidArgumentException('point data is not an array. It should be an array of 2 coordinates.');
} else {
if (count($data) !== 2) {
throw new InvalidArgumentException('point data is not an array of 2 elements. It should be an array of 2 coordinates.');
} else {
return Point::fromLonLat($data[0], $data[1]);
}
}
}
}