Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\Serializer\Normalizer; Chris@14: Chris@14: trait ObjectToPopulateTrait Chris@14: { Chris@14: /** Chris@14: * Extract the `object_to_populate` field from the context if it exists Chris@14: * and is an instance of the provided $class. Chris@14: * Chris@14: * @param string $class The class the object should be Chris@14: * @param $context The denormalization context Chris@14: * @param string $key They in which to look for the object to populate. Chris@14: * Keeps backwards compatibility with `AbstractNormalizer`. Chris@14: * Chris@14: * @return object|null an object if things check out, null otherwise Chris@14: */ Chris@14: protected function extractObjectToPopulate($class, array $context, $key = null) Chris@14: { Chris@14: $key = $key ?: 'object_to_populate'; Chris@14: Chris@17: if (isset($context[$key]) && \is_object($context[$key]) && $context[$key] instanceof $class) { Chris@14: return $context[$key]; Chris@14: } Chris@14: Chris@14: return null; Chris@14: } Chris@14: }