Completed
Push — EZP-31681 ( 54659b...e049ce )
by
unknown
18:38 queued 10s
created

getAllowedProperties()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\MVC\Symfony\Component\Serializer;
8
9
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
10
11
abstract class AbstractPropertyWhitelistNormalizer extends PropertyNormalizer
12
{
13
    public function normalize($object, $format = null, array $context = [])
14
    {
15
        $data = parent::normalize($object, $format, $context);
16
        foreach (array_keys($data) as $property) {
17
            if (!in_array($property, $this->getAllowedProperties())) {
18
                unset($data[$property]);
19
            }
20
        }
21
22
        return $data;
23
    }
24
25
    /**
26
     * @return string[]
27
     */
28
    abstract protected function getAllowedProperties();
29
}
30