Lemon\RestBundle\Object\Processor::processExclusions PHP Method

processExclusions() protected method

protected processExclusions ( object $object, object | null $entity )
$object object
$entity object | null
    protected function processExclusions($object, $entity)
    {
        $class = get_class($object);
        if (!$entity) {
            return;
        }
        $reflection = new \ReflectionClass($class);
        /** Backfill data that is ignored or read only from the serializer */
        $metadata = $this->metadataFactory->getMetadataForClass($class);
        foreach ($reflection->getProperties() as $property) {
            $name = $property->getName();
            if (!isset($metadata->propertyMetadata[$name]) || $metadata->propertyMetadata[$name]->readOnly) {
                $property->setAccessible(true);
                $property->setValue($object, $property->getValue($entity));
            }
        }
        $em = $this->doctrine->getManagerForClass($class);
        /** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata */
        $metadata = $em->getMetadataFactory()->getMetadataFor($class);
        // Look for relationships, compare against preloaded entity
        foreach ($metadata->getAssociationNames() as $fieldName) {
            if ($metadata->isCollectionValuedAssociation($fieldName)) {
                $property = $reflection->getProperty($fieldName);
                $property->setAccessible(true);
                if ($property->getValue($object)) {
                    foreach ($property->getValue($object) as $i => $value) {
                        $v = $property->getValue($entity);
                        $this->processExclusions($value, $v[$i]);
                    }
                }
            }
        }
    }