@param   EntityStructure $definition The entity structure

@return  void
506234
private function resolveHasOneOrMany($definition)
    {
        foreach (array_merge($definition->relations['hasMany'], $definition->relations['hasOne']) as $relation) {
            $counterMeta      = $this->getMeta($relation->entity);
            $counterRelations = $counterMeta->relations;

            foreach ($counterRelations['belongsTo'] as $belongsTo) {
                if ($belongsTo->entity == $definition->name && $belongsTo->reference == $relation->reference) {
                    break 2;
                }
            }

            // No existing counter-relation found; create it.
            $belongsTo = new BelongsTo(
                [
                    'name'      => $this->normalise($definition->name),
                    'entity'    => $definition->name,
                    'reference' => $relation->reference,
                ]
            );

            $this->entityDefinitions[$counterMeta->name]->relations['belongsTo'][$belongsTo->name] = $belongsTo;
        }
    }
247233
protected function configureDefinition(EntityDefinition $definition, array $crud)
    {
        $toConfigure = [
            'deleteCascade',
            'listFields',
            'filter',
            'childrenLabelFields',
            'pageSize',
            'initialSortField',
            'initialSortAscending',
            'navBarGroup',
            'optimisticLocking',
            'hardDeletion',
        ];
        foreach ($toConfigure as $field) {
            if (array_key_exists($field, $crud)) {
                $function = 'set'.ucfirst($field);
                $definition->$function($crud[$field]);
            }
        }
    }
82419
public function setEntity($entity, $entityId)
    {
        //set the entity
        $method = 'set'.ucfirst($entityId);

        //set the entity
        call_user_func([$this, $method], $entity);
    }
1333773
protected function addForeign(String $definition)
	{
		$this->runQueryWithExpression(Expressions::addForeign($this->tableName, $definition));
	}
478216
public function build(Entity $entity): void
    {
        $attributes = $entity->getEntityAttributes();

        // We will manually add a relationship for every attribute registered
        // of this entity. Once we know the relation method we have to use,
        // we will just add it to the entityAttributeRelations property.
        foreach ($attributes as $attribute) {
            $relation = $this->getRelationClosure($entity, $attribute);

            $entity->setEntityAttributeRelation($attribute->getAttribute('slug'), $relation);
        }
    }
384762
public function setDefinition(string $fqn, Definition $definition)
    {
        $parts = $this->splitFqn($fqn);
        $this->indexDefinition(0, $parts, $this->definitions, $definition);

        $this->emit('definition-added');
    }
317437
public function mapEntities(array $entityDefinitions)
	{
		foreach($entityDefinitions as $entityIdentifier => $entityDefinition)
		{
			$this->validateAndCompleteEntity($entityIdentifier, $entityDefinition);
		}
	}
706343
public function delete(EntityDefinition $definition, array $ids, WriteContext $writeContext): DeleteResult
    {
        $this->validateWriteInput($ids);

        $commandQueue = new WriteCommandQueue();

        $fields = $definition->getPrimaryKeys();

        $resolved = [];
        foreach ($ids as $raw) {
            $mapped = [];

            /** @var Field $field */
            foreach ($fields as $field) {
                if (!($field instanceof StorageAware)) {
                    continue;
                }

                if (array_key_exists($field->getPropertyName(), $raw)) {
                    $mapped[$field->getStorageName()] = $raw[$field->getPropertyName()];
                    continue;
                }

                if ($field instanceof ReferenceVersionField) {
                    $mapped[$field->getStorageName()] = $writeContext->getContext()->getVersionId();
                    continue;
                }

                if ($field instanceof VersionField) {
                    $mapped[$field->getStorageName()] = $writeContext->getContext()->getVersionId();
                    continue;
                }

                $fieldKeys = $fields
                    ->filter(function (Field $field) {
                        return !$field instanceof VersionField && !$field instanceof ReferenceVersionField;
                    })
                    ->map(function (Field $field) {
                        return $field->getPropertyName();
                    });

                throw new IncompletePrimaryKeyException($fieldKeys);
            }

            $resolved[] = $mapped;
        }

        if (!$definition instanceof MappingEntityDefinition) {
            $restrictions = $this->foreignKeyResolver->getAffectedDeleteRestrictions($definition, $resolved, $writeContext->getContext());

            if (!empty($restrictions)) {
                $restrictions = array_map(function ($restriction) {
                    return new RestrictDeleteViolation($restriction['pk'], $restriction['restrictions']);
                }, $restrictions);

                throw new RestrictDeleteViolationException($definition, $restrictions, $this->registry);
            }
        }

        $cascades = [];
        if (!$definition instanceof MappingEntityDefinition) {
            $cascadeDeletes = $this->foreignKeyResolver->getAffectedDeletes($definition, $resolved, $writeContext->getContext());

            $cascadeDeletes = array_column($cascadeDeletes, 'restrictions');
            foreach ($cascadeDeletes as $cascadeDelete) {
                $cascades = array_merge_recursive($cascades, $cascadeDelete);
            }

            foreach ($cascades as $affectedDefinitionClass => &$cascade) {
                $affectedDefinition = $this->registry->get($affectedDefinitionClass);

                $cascade = array_map(function ($key) use ($affectedDefinition) {
                    $payload = $key;

                    if (!\is_array($key)) {
                        $payload = ['id' => $key];
                    }

                    return new EntityWriteResult($key, $payload, $affectedDefinition, null);
                }, $cascade);
            }
        }

        $skipped = [];
        foreach ($resolved as $mapped) {
            $mappedBytes = array_map(function ($id) {
                return Uuid::fromHexToBytes($id);
            }, $mapped);

            $existence = $this->gateway->getExistence($definition, $mappedBytes, [], $commandQueue);

            if (!$existence->exists()) {
                $skipped[$definition->getClass()][] = new EntityWriteResult($mapped, $mapped, $definition, $existence);
                continue;
            }

            $commandQueue->add(
                $definition,
                new DeleteCommand(
                    $definition,
                    $mappedBytes,
                    $existence
                )
            );
        }

        $writeContext->setLanguages($this->languageLoader->loadLanguages());
        $identifiers = $this->getWriteResults($commandQueue);
        $this->gateway->execute($commandQueue->getCommandsInOrder(), $writeContext);

        return new DeleteResult(
            array_merge_recursive($identifiers, $cascades),
            $skipped
        );
    }
1335606
final public function loadFinalizedStagedFormDefinition(FinalizedStagedFormObjectDefinition $definition)
    {
        $this->formDefinition = $definition;
        $this->stagedForm     = $definition->getStagedForm();

        if (!$this->isCloningDuplicate) {
            $this->isCloningDuplicate = true;
            $this->stagedFormForClone = $definition->forInstance(clone $this)->getStagedForm();
            $this->isCloningDuplicate = false;
        }
    }
268208
public function add($schema, $definition)
    {
        if(is_array($definition)) $definition = (object)$definition;
        $this->__schemas__[$schema] = $definition;
        $this->compile();
        return $this;
    }
31457
public function setEntitiesAttribute($entities): void
    {
        static::saved(function ($model) use ($entities) {
            $this->entities()->delete();
            ! $entities || $this->entities()->createMany(array_map(function ($entity) {
                return ['entity_type' => $entity];
            }, $entities));
        });
    }
381373
public function validateQueryCreateStruct(QueryCreateStruct $queryCreateStruct): void
    {
        $this->validate(
            $queryCreateStruct,
            [
                new ParameterStruct(
                    [
                        'parameterDefinitions' => $queryCreateStruct->getQueryType(),
                    ]
                ),
            ],
            'parameterValues'
        );
    }
328667
private static function define($domainId, $definition) {
		$definition = ConfigHelper::normalizeItemConfig($domainId, $definition);
		if(!\App::$domain->has($domainId)) {
			\App::$domain->set($domainId, $definition);
		}
	}
908825
public function set(string $key, $value): void {
		if (!property_exists($this, $key)) {
			throw new EntityException(
				sprintf("Unknown property (%s) in %s.", $key, get_class()),
				EntityException::UNKNOWN_PROPERTY
			);
		}
		
		$this->{$key} = $value;
	}
612804
public function injectEntityDependencies(EntityInterface $entity): void
    {
        $this->buildEntityInjectMethodsForEntity($entity);
        $entityFqn = $this->leadingSlash($entity::getDoctrineStaticMeta()->getReflectionClass()->getName());
        $this->injectStatic($entity, $this->entityInjectMethods[$entityFqn][self::TYPE_KEY_STATIC]);
        $this->inject($entity, $this->entityInjectMethods[$entityFqn][self::TYPE_KEY_INSTANCE]);
    }
1290980
private function createStructureNodes(\DOMDocument $dom, ElementStructure $structure)
    {
        $structureNode = $dom->createElement('structure');

        $idAttr = $dom->createAttribute('id');
        $idAttr->value = $structure->getId();
        $structureNode->appendChild($idAttr);

        $dsIdAttr = $dom->createAttribute('dsId');
        $dsIdAttr->value = $structure->getDsId();
        $structureNode->appendChild($dsIdAttr);

        $parentDsIdAttr = $dom->createAttribute('parentDsId');
        $parentDsIdAttr->value = $structure->getDsId();
        $structureNode->appendChild($parentDsIdAttr);

        $nameAttr = $dom->createAttribute('name');
        $nameAttr->value = $structure->getName();
        $structureNode->appendChild($nameAttr);

        $parentNameAttr = $dom->createAttribute('parentName');
        $parentNameAttr->value = $structure->getParentName();
        $structureNode->appendChild($parentNameAttr);

        foreach ($structure->getStructures() as $childStructure) {
            $structureNode->appendChild(
                $this->createStructureNodes($dom, $childStructure)
            );
        }

        foreach ($structure->getValues() as $value) {
            $valueNode = $dom->createElement('value');

            $idAttr = $dom->createAttribute('id');
            $idAttr->value = $value->getId();
            $valueNode->appendChild($idAttr);

            $dsIdAttr = $dom->createAttribute('dsId');
            $dsIdAttr->value = $value->getDsId();
            $valueNode->appendChild($dsIdAttr);

            $languageAttr = $dom->createAttribute('language');
            $languageAttr->value = $value->getLanguage();
            $valueNode->appendChild($languageAttr);

            $nameAttr = $dom->createAttribute('name');
            $nameAttr->value = $value->getName();
            $valueNode->appendChild($nameAttr);

            $typeAttr = $dom->createAttribute('type');
            $typeAttr->value = $value->getType();
            $valueNode->appendChild($typeAttr);

            $dataTypeAttr = $dom->createAttribute('dataType');
            $dataTypeAttr->value = $value->getDataType();
            $valueNode->appendChild($dataTypeAttr);

            $rawValue = $value->getValue();
            if ($value->getDataType() === 'array') {
                $rawValue = json_encode($rawValue);
            }
            $valueNode->appendChild($dom->createCDATASection($rawValue));

            $structureNode->appendChild($valueNode);
        }

        return $structureNode;
    }
833627
public function handleRecursively(Event $event): void
    {
        $this->handle($event);

        foreach ($this->childEntities() as $entity) {
            $entity->registerAggregateRoot($this->getAggregateRoot());
            $entity->handleRecursively($event);
        }
    }