comparison vendor/symfony/serializer/Normalizer/ObjectToPopulateTrait.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Serializer\Normalizer;
13
14 trait ObjectToPopulateTrait
15 {
16 /**
17 * Extract the `object_to_populate` field from the context if it exists
18 * and is an instance of the provided $class.
19 *
20 * @param string $class The class the object should be
21 * @param $context The denormalization context
22 * @param string $key They in which to look for the object to populate.
23 * Keeps backwards compatibility with `AbstractNormalizer`.
24 *
25 * @return object|null an object if things check out, null otherwise
26 */
27 protected function extractObjectToPopulate($class, array $context, $key = null)
28 {
29 $key = $key ?: 'object_to_populate';
30
31 if (isset($context[$key]) && is_object($context[$key]) && $context[$key] instanceof $class) {
32 return $context[$key];
33 }
34
35 return null;
36 }
37 }