Completed
Push — master ( 7a35f9...4404a1 )
by Paweł
32:54 queued 23:30
created

onPreSerialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2019 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2019 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Serializer;
18
19
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
20
use JMS\Serializer\EventDispatcher\ObjectEvent;
21
use SWP\Bundle\ContentListBundle\Form\Type\ContentListType;
22
use SWP\Bundle\CoreBundle\Model\ContentList;
23
use SWP\Component\ContentList\Model\ContentListInterface;
24
25
final class ContentListSerializationSubscriber implements EventSubscriberInterface
26
{
27
    public static function getSubscribedEvents()
28
    {
29
        return [
30
            [
31
                'event' => 'serializer.pre_serialize',
32
                'class' => ContentList::class,
33
                'method' => 'onPreSerialize',
34
            ],
35
        ];
36
    }
37
38
    public function onPreSerialize(ObjectEvent $event)
39
    {
40
        $object = $event->getObject();
41
        if (!$object instanceof ContentListInterface) {
42
            return;
43
        }
44
45
        $object->setFilters(ContentListType::transformArrayKeys($object->getFilters(), 'snake'));
46
    }
47
}
48