mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-25 18:17:43 +00:00
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\MainBundle\Serializer\Normalizer;
|
|
|
|
use Chill\MainBundle\Doctrine\Model\Point;
|
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
|
|
|
use function count;
|
|
use function is_array;
|
|
|
|
class PointNormalizer implements DenormalizerInterface
|
|
{
|
|
public function denormalize($data, $type, $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.');
|
|
}
|
|
|
|
if (count($data) !== 2) {
|
|
throw new InvalidArgumentException('point data is not an array of 2 elements. It should be an array of 2 coordinates.');
|
|
}
|
|
|
|
return Point::fromLonLat($data[0], $data[1]);
|
|
}
|
|
|
|
public function supportsDenormalization($data, $type, $format = null): bool
|
|
{
|
|
return Point::class === $type;
|
|
}
|
|
}
|