| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of graze/unicontroller-client. |
||
| 4 | * |
||
| 5 | * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
||
| 6 | * |
||
| 7 | * For the full copyright and license information, please view the LICENSE |
||
| 8 | * file that was distributed with this source code. |
||
| 9 | * |
||
| 10 | * @license https://github.com/graze/unicontroller-client/blob/master/LICENSE.md |
||
| 11 | * @link https://github.com/graze/unicontroller-client |
||
| 12 | */ |
||
| 13 | namespace Graze\UnicontrollerClient\Serialiser; |
||
| 14 | |||
| 15 | use Graze\UnicontrollerClient\Entity\Entity\EntityInterface; |
||
| 16 | |||
| 17 | class SerialiserResolver |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param EntityInterface $entity |
||
| 21 | * @return Graze\UnicontrollerClient\Serialiser\Serialiser\SerialiserInterface |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 22 | */ |
||
| 23 | 19 | public function resolve(EntityInterface $entity) |
|
| 24 | { |
||
| 25 | 19 | $nameEntity = get_class($entity); |
|
| 26 | 19 | $nameEntityShort = substr($nameEntity, strrpos($nameEntity, 'Entity') + 6); |
|
| 27 | |||
| 28 | 19 | $serialiserName = sprintf('Graze\\UnicontrollerClient\\Serialiser\\Serialiser\\Serialiser%s', $nameEntityShort); |
|
| 29 | 19 | if (!class_exists($serialiserName)) { |
|
| 30 | throw new \OutOfBoundsException(sprintf('no serialiser defined for entity [%s]', $nameEntity)); |
||
| 31 | } |
||
| 32 | |||
| 33 | 19 | return $serialiserName::factory(); |
|
| 34 | } |
||
| 35 | } |
||
| 36 |