owncourses /
courses-server
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace App\Serializer; |
||
| 6 | |||
| 7 | use App\Model\LessonInterface; |
||
| 8 | use App\Serializer\Processor\FileHrefProcessor; |
||
| 9 | use App\Serializer\Processor\LessonCompletedProcessor; |
||
| 10 | use App\Serializer\Processor\LessonPaginationProcessor; |
||
| 11 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
||
| 12 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; |
||
| 13 | |||
| 14 | class LessonNormalizer implements NormalizerInterface |
||
| 15 | { |
||
| 16 | private $normalizer; |
||
| 17 | private $fileHrefProcessor; |
||
| 18 | private $lessonCompletedProcessor; |
||
| 19 | private $lessonPaginationProcessor; |
||
| 20 | |||
| 21 | public function __construct( |
||
| 22 | ObjectNormalizer $normalizer, |
||
| 23 | FileHrefProcessor $fileHrefProcessor, |
||
| 24 | LessonCompletedProcessor $lessonCompletedProcessor, |
||
| 25 | LessonPaginationProcessor $lessonPaginationProcessor |
||
| 26 | ) { |
||
| 27 | $this->normalizer = $normalizer; |
||
| 28 | $this->fileHrefProcessor = $fileHrefProcessor; |
||
| 29 | $this->lessonCompletedProcessor = $lessonCompletedProcessor; |
||
| 30 | $this->lessonPaginationProcessor = $lessonPaginationProcessor; |
||
| 31 | } |
||
| 32 | |||
| 33 | public function normalize($object, $format = null, array $context = []) |
||
| 34 | { |
||
| 35 | $data = $this->normalizer->normalize($object, $format, $context); |
||
| 36 | $data = $this->fileHrefProcessor->process($object, $data); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 37 | $data = $this->lessonCompletedProcessor->process($object, $data); |
||
| 38 | $data = $this->lessonPaginationProcessor->process($object, $data); |
||
| 39 | |||
| 40 | return $data; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function supportsNormalization($data, $format = null): bool |
||
| 44 | { |
||
| 45 | return $data instanceof LessonInterface; |
||
| 46 | } |
||
| 47 | } |
||
| 48 |