mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
address: POST an address
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user