getFlag example

static::assertNotEquals('0000-00-00 00:00:00', $product['updated_at']);
        static::assertNotEquals('2011-01-01 15:03:01', $product['updated_at']);

        static::assertNotEquals('0000-00-00 00:00:00', $product['created_at']);
        static::assertNotEquals('2011-01-01 15:03:01', $product['created_at']);
        static::assertNotEquals('0000-00-00 00:00:00', $newProduct['created_at']);
        static::assertNotEquals('2011-01-01 15:03:01', $newProduct['created_at']);
    }

    public function testInsertIgnoresRuntimeFields(): void
    {
        static::assertNotNull($this->getContainer()->get(MediaDefinition::class)->getFields()->get('url')->getFlag(Runtime::class));
        $id = '2b9a945bb62b4122a32a3bbfbe1e6fd3';
        $writeContext = $this->createWriteContext();
        $this->getWriter()->insert(
            $this->getContainer()->get(MediaDefinition::class),
            [
                [
                    'id' => $id,
                    'name' => 'Test media',
                    'fileName' => 'testFile',
                    'mimeType' => 'image/jpeg',
                    'fileExtension' => 'jpg',
                    


        $associations = [];
        foreach ($variables as $variable) {
            $fields = EntityDefinitionQueryHelper::getFieldsOfAccessor($definition$variable, true);

            /** @var Field|null $lastField */
            $lastField = end($fields);

            $runtime = new Runtime();

            if ($lastField && $lastField->getFlag(Runtime::class)) {
                $associations = array_merge($associations$runtime->getDepends());
            }

            $associations[] = EntityDefinitionQueryHelper::getAssociationPath($variable$definition);
        }

        return array_filter(array_unique($associations));
    }
}
foreach ($setNulls as $affectedDefinitionClass => $restrictions) {
            [$entity$field] = explode('.', $affectedDefinitionClass);

            $affectedDefinition = $this->registry->getByEntityName($entity);

            /** @var AssociationField $associationField */
            $associationField = $setNullFields
                ->filter(fn (Field $setNullField) => $setNullField instanceof AssociationField && $setNullField->getReferenceField() === $field)
                ->first();

            /** @var SetNullOnDelete $flag */
            $flag = $associationField->getFlag(SetNullOnDelete::class);

            foreach ($restrictions as $key) {
                $payload = ['id' => Uuid::fromHexToBytes($key)$field => null];

                $primary = EntityHydrator::encodePrimaryKey($affectedDefinition['id' => $key]$writeContext->getContext());

                $existence = new EntityExistence($affectedDefinition->getEntityName()$primary, true, false, false, []);

                if ($definition->isVersionAware()) {
                    $versionField = str_replace('_id', '_version_id', $field);
                    $payload[$versionField] = null;
                }
$definition = $this->parser->parse($file->getContents());

                $issues = $this->validator->validate($definition);
                if ($issues->count()) {
                    $messages = \array_map(static fn (ConstraintViolationInterface $violation) => $violation->getMessage(), \iterator_to_array($issues));

                    throw new \InvalidArgumentException(\sprintf('Invalid file at path: %s, errors: %s', $file->getRealPath(), \implode(', ', $messages)));
                }

                $featureFlagDefaultOn = false;

                if ($definition->getFlag()) {
                    $featureFlagDefaultOn = $this->featureFlags[$definition->getFlag()]['default'] ?? false;
                }

                if (!$featureFlagDefaultOn && !$includeFeatureFlags && $definition->getFlag()) {
                    continue;
                }

                $changelog = (new ChangelogFile())
                    ->setName($file->getFilename())
                    ->setPath((string) $file->getRealPath())
                    ->setDefinition($definition);

                
public function addNewField(Field $field): void
    {
        $field->compile($this->registry);
        $this->addField($field);
    }

    public function addField(Field $field): void
    {
        $this->elements[$field->getPropertyName()] = $field;

        if ($field instanceof StorageAware && !$field->getFlag(Runtime::class)) {
            $this->mappedByStorageName[$field->getStorageName()] = $field;
        }

        if ($field instanceof ChildrenAssociationField) {
            $this->childrenAssociationField = $field;
        }

        if ($field instanceof TranslatedField) {
            $this->translatedFields[$field->getPropertyName()] = $field;
        }

        
return;
        }

        if ($field instanceof AssociationField) {
            return;
        }

        if ($field instanceof TranslatedField) {
            return;
        }

        if ($field->getFlag(Computed::class)) {
            return;
        }

        if ($field instanceof DateField || $field instanceof DateTimeField) {
            if ($value instanceof \DateTimeInterface) {
                $value = $value->format(Defaults::STORAGE_DATE_TIME_FORMAT);
            }

            if (empty($value)) {
                return null;
            }

            
->first();

        if ($reverseSide === null) {
            $associationViolations[$definition->getClass()][] = sprintf(
                'Missing reverse one-to-many association for %s <-> %s (%s)',
                $definition->getClass(),
                $association->getReferenceDefinition()->getClass(),
                $association->getPropertyName()
            );
        }

        if ($association->getFlag(CascadeDelete::class)) {
            $associationViolations[$definition->getClass()][] = sprintf(
                'Remove cascade delete in definition %s association: %s. Many to one association should not have a cascade delete',
                $definition->getClass(),
                $association->getPropertyName()
            );
        }

        $versionError = $this->validateVersionAwareness($reference$definition$association);
        if ($versionError) {
            $associationViolations[$definition->getClass()][] = $versionError;
        }

        

    public function testData(string $inFile, array $expectedData, string $outFile, int $expectedExceptions): void
    {
        $parser = self::getContainer()->get(ChangelogParser::class);

        $logEntry = $parser->parse((string) file_get_contents($inFile));

        static::assertSame($expectedData['title']$logEntry->getTitle());
        static::assertSame($expectedData['issue']$logEntry->getIssue());
        static::assertSame($expectedData['flag']$logEntry->getFlag());
        static::assertSame($expectedData['author']$logEntry->getAuthor());
        static::assertSame($expectedData['authorEmail']$logEntry->getAuthorEmail());
        static::assertSame($expectedData['authorGithub']$logEntry->getAuthorGitHub());
        static::assertSame($expectedData['core']$logEntry->getCore());
        static::assertSame($expectedData['storefront']$logEntry->getStorefront());
        static::assertSame($expectedData['admin']$logEntry->getAdministration());
        static::assertSame($expectedData['api']$logEntry->getApi());
        static::assertSame($expectedData['upgrade']$logEntry->getUpgradeInformation());
        static::assertSame($expectedData['major']$logEntry->getNextMajorVersionChanges());
        $lines = file($outFile);
        static::assertIsArray($lines);

        
private function getReferenceColumn(FieldResolverContext $context, ManyToManyAssociationField $field): string
    {
        if (!$field->is(ReverseInherited::class)) {
            return EntityDefinitionQueryHelper::escape($field->getReferenceField());
        }

        if (!$context->getContext()->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($field->getReferenceField());
        }

        /** @var ReverseInherited $flag */
        $flag = $field->getFlag(ReverseInherited::class);

        return EntityDefinitionQueryHelper::escape($flag->getReversedPropertyName());
    }

    private function buildVersionWhere(EntityDefinition $definition, ManyToManyAssociationField $field): string
    {
        if (!$definition->isVersionAware()) {
            return '';
        }
        if (!$field->is(CascadeDelete::class)) {
            return '';
        }
protected function sanitize(HtmlSanitizer $sanitizer, KeyValuePair $data, Field $field, EntityExistence $existence): ?string
    {
        if ($data->getValue() === null) {
            return null;
        }

        if (!$field->is(AllowHtml::class)) {
            return strip_tags((string) $data->getValue());
        }

        $flag = $field->getFlag(AllowHtml::class);

        if ($flag instanceof AllowHtml && $flag->isSanitized()) {
            $fieldKey = sprintf('%s.%s', (string) $existence->getEntityName()$field->getPropertyName());

            return $sanitizer->sanitize((string) $data->getValue()[], false, $fieldKey);
        }

        return (string) $data->getValue();
    }
}
EntityDefinitionQueryHelper::escape($subRoot),
        );
        $queryHelper->joinVersion($versionQuery$field->getReferenceDefinition()$subRoot$context);

        return $versionQuery;
    }

    private function getReferenceColumn(AssociationField $field, Context $context): string
    {
        if ($field->is(ReverseInherited::class) && $context->considerInheritance()) {
            /** @var ReverseInherited $flag */
            $flag = $field->getFlag(ReverseInherited::class);

            return EntityDefinitionQueryHelper::escape($flag->getReversedPropertyName());
        }

        return EntityDefinitionQueryHelper::escape($field->getReferenceField());
    }

    /** * Adds a left join with a sub-select to the query that results in the entity version requested in the context or the * live version if that version does not exist. * * @param string $root e.g. "document" * @param string $alias e.g. "document.order" * @param string $source e.g. "document.order_id * @param string $referenceColumn e.g. "id" (for the order) */
if ($field->is(Inherited::class) && $context->getContext()->considerInheritance()) {
            return EntityDefinitionQueryHelper::escape($context->getAlias()) . '.' . EntityDefinitionQueryHelper::escape($field->getPropertyName());
        }

        return EntityDefinitionQueryHelper::escape($context->getAlias()) . '.' . EntityDefinitionQueryHelper::escape($field->getLocalField());
    }

    private function getReferenceColumn(FieldResolverContext $context, OneToManyAssociationField $field): string
    {
        if ($field->is(ReverseInherited::class) && $context->getContext()->considerInheritance()) {
            /** @var ReverseInherited $flag */
            $flag = $field->getFlag(ReverseInherited::class);

            return EntityDefinitionQueryHelper::escape($flag->getReversedPropertyName());
        }

        return EntityDefinitionQueryHelper::escape($field->getReferenceField());
    }
}
foreach ($definition->getFields() as $propertyName => $field) {
            if ($propertyName === 'id') {
                continue;
            }

            if (!$fields->isAllowed($definition->getEntityName()$propertyName)) {
                continue;
            }

            /** @var ApiAware|null $flag */
            $flag = $field->getFlag(ApiAware::class);

            if ($flag === null || !$flag->isBaseUrlAllowed($result->getBaseUrl())) {
                continue;
            }

            if ($field instanceof AssociationField) {
                $isSingle = $field instanceof ManyToOneAssociationField || $field instanceof OneToOneAssociationField;

                $reference = $field->getReferenceDefinition();
                if ($field instanceof ManyToManyAssociationField) {
                    $reference = $field->getToManyReferenceDefinition();
                }

        $kernel->boot();
        $registry = $kernel->getContainer()->get(DefinitionInstanceRegistry::class);

        $mapping = [];

        foreach ($registry->getDefinitions() as $definition) {
            $entity = $definition->getEntityName();

            foreach ($definition->getFields() as $field) {
                /** @var ApiAware|null $flag */
                $flag = $field->getFlag(ApiAware::class);
                if ($flag === null) {
                    continue;
                }

                if ($flag->isSourceAllowed(SalesChannelApiSource::class)) {
                    $mapping[] = $entity . '.' . $field->getPropertyName();
                }
            }
        }

        // file_put_contents(__DIR__ . '/fixtures/api-aware-fields.json', json_encode($mapping, JSON_PRETTY_PRINT));
/** * @param array<string> $ids */
    private function updateToManyAssociations(EntityDefinition $definition, array $ids, FieldCollection $associations, Context $context): void
    {
        $bytes = array_map(fn ($id) => Uuid::fromHexToBytes($id)$ids);

        /** @var AssociationField $association */
        foreach ($associations as $association) {
            $reference = $association->getReferenceDefinition();

            $flag = $association->getFlag(Inherited::class);

            if (!$flag instanceof Inherited) {
                throw new \RuntimeException(\sprintf('Association %s is not marked as inherited', $definition->getEntityName() . '.' . $association->getPropertyName()));
            }

            $foreignKey = $flag->getForeignKey() ?: ($definition->getEntityName() . '_id');

            $versionKey = \substr($foreignKey, 0, -3) . '_version_id';

            $sql = sprintf(
                'UPDATE #root# SET #property# = IFNULL( ( SELECT #reference#.#entity_id# FROM #reference# WHERE #reference#.#entity_id# = #root#.id %s LIMIT 1 ), IFNULL(#root#.parent_id, #root#.id) ) WHERE #root#.id IN (:ids) %s',
Home | Imprint | This part of the site doesn't use cookies.