filterInstance example

return $query->executeQuery()->fetchAllAssociative();
    }

    private function updateTree(array $entity, EntityDefinition $definition, Context $context): string
    {
        $query = $this->connection->createQueryBuilder();
        $escaped = EntityDefinitionQueryHelper::escape($definition->getEntityName());
        $query->update($escaped);

        /** @var TreePathField $pathField */
        foreach ($definition->getFields()->filterInstance(TreePathField::class) as $pathField) {
            $path = 'null';

            if (\array_key_exists('parent', $entity)) {
                $path = '"|' . implode('|', $this->buildPathArray($entity['parent']$pathField)) . '|"';
            }

            $query->set($pathField->getStorageName()$path);
        }

        /** @var TreeLevelField $field */
        foreach ($definition->getFields()->filterInstance(TreeLevelField::class) as $field) {
            
/** * @internal * * @extends Collection<RequirementCheck> */
#[Package('core')] class RequirementsCheckCollection extends Collection
{
    public function getPathChecks(): self
    {
        return $this->filterInstance(PathCheck::class);
    }

    public function getSystemChecks(): self
    {
        return $this->filterInstance(SystemCheck::class);
    }

    public function hasError(): bool
    {
        return $this->filter(static fn (RequirementCheck $check): bool => $check->getStatus() === RequirementCheck::STATUS_ERROR)->first() !== null;
    }

    


                    $extensions[$propertyName] = ['type' => $type, 'entity' => $entity];
                }

                $properties['extensions']['properties'] = $extensions;
            }

            $entityName = $definition->getEntityName();
            $schemaDefinitions[$entityName] = [
                'name' => $entityName,
                'translatable' => $definition->getFields()->filterInstance(TranslatedField::class)->getKeys(),
                'properties' => $properties,
            ];
        }

        return $schemaDefinitions;
    }

    private function getResourceUri(EntityDefinition $definition, string $rootPath = '/'): string
    {
        return ltrim('/', $rootPath) . '/' . str_replace('_', '-', $definition->getEntityName());
    }

    


    public function decode(Field $field, mixed $value): never
    {
        throw new DecodeByHydratorException($field);
    }

    private function getMappingAssociation(
        EntityDefinition $referencedDefinition,
        ManyToManyAssociationField $field
    ): ?ManyToOneAssociationField {
        $associations = $referencedDefinition->getFields()->filterInstance(ManyToOneAssociationField::class);

        /** @var ManyToOneAssociationField $association */
        foreach ($associations as $association) {
            if ($association->getStorageName() === $field->getMappingReferenceColumn()) {
                return $association;
            }
        }

        return null;
    }

    
public function update(string $entity, array $ids, Context $context, ?string $propertyName = null): void
    {
        $definition = $this->registry->getByEntityName($entity);

        if (empty($ids)) {
            return;
        }

        $ids = array_unique($ids);

        if ($definition instanceof MappingEntityDefinition) {
            $fkFields = $definition->getFields()->filterInstance(FkField::class);

            /** @var FkField $field */
            foreach ($fkFields as $field) {
                $foreignKeys = array_column($ids$field->getPropertyName());
                $this->update($field->getReferenceDefinition()->getEntityName()$foreignKeys$context);
            }

            return;
        }

        $fields = $definition->getFields()->filterInstance(ManyToManyIdField::class);

        


                $lineItem = $this->promotionItemBuilder->buildPlaceholderItem($code);

                $cart = $this->cartService->add($cart$lineItem$context);

                // we basically show all cart errors or notices                 // at the moments its not possible to show success messages with "green" color                 // from the cart...thus it has to be done in the storefront level                 // so if we have an promotion added notice, we simply convert this to                 // a success flash message                 $addedEvents = $cart->getErrors()->filterInstance(PromotionCartAddedInformationError::class);
                if ($addedEvents->count() > 0) {
                    $this->addFlash(self::SUCCESS, $this->trans('checkout.codeAddedSuccessful'));

                    return $this->createActionResponse($request);
                }

                // if we have no custom error message above                 // then simply continue with the default display                 // of the cart errors and notices                 $this->traceErrors($cart);
            } catch (\Exception) {
                
static::assertInstanceOf(ShippingMethodEntity::class$shippingMethod);
                    static::assertSame('fallback-shipping-method-name', $shippingMethod->getName());
                }
            );

        $cartFacade = $this->getStorefrontCartFacade(
            $cart,
            $this->callbackShippingMethodSwitcherReturnFallbackMethod(...)
        );
        $returnedCart = $cartFacade->get('', $salesChannelContext);

        $filtered = $errorCollection->filterInstance(ShippingMethodChangedError::class);
        static::assertCount(1, $filtered);
        $error = $filtered->first();
        static::assertInstanceOf(ShippingMethodChangedError::class$error);
        static::assertSame([
            'newShippingMethodName' => 'fallback-shipping-method-name',
            'oldShippingMethodName' => 'original-shipping-method-name',
        ]$error->getParameters());

        $controlCart = $this->getCart();
        $controlCart->setErrors($this->getCartErrorCollection(true));
        static::assertNotEquals($controlCart$returnedCart);
    }

        $fields = $definition->getFields()->filter(
            function DField $field) {
                if (!$field instanceof ManyToOneAssociationField) {
                    return false;
                }

                return true;
            }
        );

        $referenceVersionFields = $definition->getFields()->filterInstance(ReferenceVersionField::class);

        $indices = [];
        $constraints = [];

        /** @var ManyToOneAssociationField $field */
        foreach ($fields as $field) {
            $reference = $field->getReferenceDefinition();

            $hasOneToMany = $definition->getFields()->filter(function DField $field) use ($reference) {
                if (!$field instanceof OneToManyAssociationField) {
                    return false;
                }
new FalseRule(),
                ]),
            ]),
        ]);

        static::assertTrue($collection->has(FalseRule::class));
        static::assertTrue($collection->has(OrRule::class));
        static::assertEquals(
            new RuleCollection([
                new FalseRule(),
            ]),
            $collection->filterInstance(FalseRule::class)
        );
    }
}
$vars = [
            '#namespace#' => $this->getNamespace($definition),
            '#class#' => $this->getClass($definition),
        ];

        return str_replace(array_keys($vars)array_values($vars)$template);
    }

    private function generate(EntityDefinition $definition): string
    {
        $order = array_merge(
            $definition->getFields()->filterInstance(StorageAware::class)->getElements(),
            $definition->getFields()->filterInstance(TranslatedField::class)->getElements(),
            $definition->getFields()->filterInstance(ManyToOneAssociationField::class)->getElements(),
            $definition->getFields()->filterInstance(OneToOneAssociationField::class)->getElements(),
            $definition->getFields()->filterInstance(ManyToManyAssociationField::class)->getElements(),
            $definition->getFields()->getElements(),
        );

        $fields = [];
        $calls = [];

        $handled = [];
        
return $this->definition
            ->getFields()
            ->filterByFlag(RuleAreas::class);
    }

    /** * @return FkField[] */
    private function getForeignKeyFields(EntityDefinition $definition): array
    {
        /** @var FkField[] $fields */
        $fields = $definition->getFields()->filterInstance(FkField::class)->filter(fn (FkField $fk): bool => $fk->getReferenceDefinition()->getEntityName() === $this->definition->getEntityName())->getElements();

        return $fields;
    }

    /** * @return string[] */
    private function getAssociationEntities(): array
    {
        return $this->getAssociationFields()->filter(fn (AssociationField $associationField): bool => $associationField instanceof OneToManyAssociationField)->map(fn (AssociationField $field): string => $field->getReferenceDefinition()->getEntityName());
    }

    
$collection->sort(fn ($a$b) => strcmp((string) $a(string) $b));

        static::assertEquals([2 => 'a', 0 => 'b', 1 => 'c']$collection->getElements());
    }

    public function testFilterInstance(): void
    {
        $productStruct = new ProductEntity();
        $categoryStruct = new CategoryEntity();
        $collection = new TestCollection();
        static::assertEquals(0, $collection->filterInstance(ProductEntity::class)->count());

        $collection->add('a');
        $collection->add($productStruct);
        $collection->add($categoryStruct);

        $filtered = $collection->filterInstance(Struct::class);
        static::assertEquals([$productStruct$categoryStruct]array_values($filtered->getElements()));
    }

    public function testFilter(): void
    {
        
if ($flag === null) {
                return false;
            }

            return $flag->isSourceAllowed($context->getSource()::class);
        });

        if ($fields->count() > 0) {
            return $fields;
        }

        $fields = $definition->getFields()->filterInstance(TranslatedField::class);
        if ($fields->count() > 0) {
            return $fields;
        }

        /** @var FieldCollection $field */
        $field = $definition->getFields()->filterInstance(StringField::class);

        return $field;
    }

    private function validateDateFormat(string $format, string $date): bool
    {


        return $content;
    }

    private function getKeyByManyToMany(ManyToManyAssociationField $field): ?string
    {
        $referenceDefinition = $field->getReferenceDefinition();

        /** @var ManyToManyAssociationField|null $manyToMany */
        $manyToMany = $field->getToManyReferenceDefinition()->getFields()
            ->filterInstance(ManyToManyAssociationField::class)
            ->filter(static fn (ManyToManyAssociationField $field) => $field->getReferenceDefinition() === $referenceDefinition)
            ->first();

        if (!$manyToMany) {
            return null;
        }

        return $manyToMany->getPropertyName() . '.' . $manyToMany->getReferenceField();
    }

    private function getKeyByOneToMany(OneToManyAssociationField $field): ?string
    {
public function __construct(private readonly DefinitionInstanceRegistry $definitionRegistry)
    {
    }

    #[Route(path: '/api/_action/attribute-set/relations', name: 'api.action.attribute-set.get-relations', methods: ['GET'])]     public function getAvailableRelations(): JsonResponse
    {
        $definitions = $this->definitionRegistry->getDefinitions();

        $entityNames = [];
        foreach ($definitions as $definition) {
            if (\count($definition->getFields()->filterInstance(CustomFields::class)) === 0) {
                continue;
            }
            if ($definition instanceof EntityTranslationDefinition) {
                $definition = $definition->getParentDefinition();
            }
            $entityNames[] = $definition->getEntityName();
        }
        sort($entityNames);

        return new JsonResponse($entityNames);
    }
}
Home | Imprint | This part of the site doesn't use cookies.