getFilters example


    public function getFilters(): array
    {
        return $this->extensionSet->getFilters();
    }

    public function addTest(TwigTest $test)
    {
        $this->extensionSet->addTest($test);
    }

    /** * @return TwigTest[] * * @internal */
$criteria->addFilter(new ContainsFilter('configurationKey', 'core'));
        $criteria->setLimit(1);

        /** @var RepositoryIterator<SystemConfigCollection> $iterator */
        $iterator = new RepositoryIterator($systemConfigRepository$context$criteria);

        $offset = 1;
        while (($result = $iterator->fetch()) !== null) {
            static::assertNotEmpty($result->getEntities()->first()?->getId());
            static::assertEquals(
                [new ContainsFilter('configurationKey', 'core')],
                $criteria->getFilters()
            );
            static::assertCount(0, $criteria->getPostFilters());
            static::assertEquals($offset$criteria->getOffset());
            ++$offset;
        }
    }

    public function testFetchIdsIsNotRunningInfinitely(): void
    {
        $context = Context::createDefaultContext();
        /** @var EntityRepository<SystemConfigCollection> $systemConfigRepository */
        
$this->request->setLocale($this->router->getLocale());
        }

        $this->benchmark->stop('routing');

        // for backward compatibility         $multipleFiltersEnabled = config(Feature::class)->multipleFilters ?? false;
        if ($multipleFiltersEnabled) {
            return $this->router->getFilter();
        }

        return $this->router->getFilters();
    }

    /** * Determines the path to use for us to try to route to, based * on the CLI/IncomingRequest path. * * @return string */
    protected function determinePath()
    {
        if (empty($this->path)) {
            
$filters = $this->groupFilters($definition$criteria$paths);

        $this->criteriaPartResolver->resolve($filters$definition$query$context);

        $this->criteriaPartResolver->resolve($criteria->getQueries()$definition$query$context);

        $this->criteriaPartResolver->resolve($criteria->getSorting()$definition$query$context);

        // do not use grouped filters, because the grouped filters are mapped flat and the logical OR/AND are removed         $filter = new AndFilter(array_merge(
            $criteria->getFilters(),
            $criteria->getPostFilters()
        ));

        $this->addFilter($definition$filter$query$context);

        $this->addQueries($definition$criteria$query$context);

        if ($criteria->getLimit() === 1) {
            $query->removeState(EntityDefinitionQueryHelper::HAS_TO_MANY_JOIN);
        }

        

    protected function generateFilterConditionSQL(ClassMetadata $targetEntity$targetTableAlias)
    {
        $filterClauses = [];

        foreach ($this->em->getFilters()->getEnabledFilters() as $filter) {
            $filterExpr = $filter->addFilterConstraint($targetEntity$targetTableAlias);
            if ($filterExpr !== '') {
                $filterClauses[] = '(' . $filterExpr . ')';
            }
        }

        $sql = implode(' AND ', $filterClauses);

        return $sql ? '(' . $sql . ')' : ''; // Wrap again to avoid "X or Y and FilterConditionSQL"     }

    

    private function _read(
        Criteria $criteria,
        EntityDefinition $definition,
        Context $context,
        EntityCollection $collection,
        FieldCollection $fields,
        bool $performEmptySearch = false,
        array $partial = []
    ): EntityCollection {
        $hasFilters = !empty($criteria->getFilters()) || !empty($criteria->getPostFilters());
        $hasIds = !empty($criteria->getIds());

        if (!$performEmptySearch && !$hasFilters && !$hasIds) {
            return $collection;
        }

        if ($partial !== []) {
            $fields = $definition->getFields()->filter(function DField $field) use (&$partial) {
                if ($field->getFlag(PrimaryKey::class)) {
                    $partial[$field->getPropertyName()] = [];

                    
if (stripos($attributes, 'method=') === false) {
            $attributes .= ' method="post"';
        }
        if (stripos($attributes, 'accept-charset=') === false) {
            $config = config(App::class);
            $attributes .= ' accept-charset="' . strtolower($config->charset) . '"';
        }

        $form = '<form action="' . $action . '"' . $attributes . ">\n";

        // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites         $before = Services::filters()->getFilters()['before'];

        if ((in_array('csrf', $before, true) || array_key_exists('csrf', $before)) && strpos($actionbase_url()) !== false && ! stripos($form, 'method="get"')) {
            $form .= csrf_field($csrfId ?? null);
        }

        foreach ($hidden as $name => $value) {
            $form .= form_hidden($name$value);
        }

        return $form;
    }
}
$criteria = new Criteria();
        $criteria->setLimit(50);

        $context = Context::createDefaultContext();

        $constraint = new EntityExists(
            ['context' => $context, 'entity' => LocaleDefinition::ENTITY_NAME, 'criteria' => $criteria]
        );

        $validator->validate(Uuid::randomHex()[$constraint]);

        static::assertCount(0, $criteria->getFilters());
        static::assertSame(50, $criteria->getLimit());
    }

    public function testValidatorWorks(): void
    {
        $repository = $this->createRepository(LocaleDefinition::class);

        $context = Context::createDefaultContext();
        $id1 = Uuid::randomHex();
        $id2 = Uuid::randomHex();

        
Context::createDefaultContext()
                )
            );
        }

        $productDownload = new ProductDownloadEntity();
        $productDownload->setId(Uuid::randomHex());
        $productDownload->setMediaId(Uuid::randomHex());
        $productDownload->setPosition(0);
        $productDownloadRepository = $this->createMock(EntityRepository::class);
        $productDownloadRepository->method('search')->willReturnCallback(function DCriteria $criteria) use ($productDownload): EntitySearchResult {
            $filters = $criteria->getFilters();
            if (isset($filters[0]) && $filters[0] instanceof EqualsAnyFilter) {
                $value = ReflectionHelper::getPropertyValue($filters[0], 'value');
                $productDownload->setProductId($value[0] ?? null);
            }

            return new EntitySearchResult(
                'productDownload',
                1,
                new EntityCollection([$productDownload]),
                null,
                new Criteria(),
                
fn ($error) => $error instanceof ShippingMethodChangedError
        );

        static::assertCount(0, $errorCollectionFiltered);
    }

    public function callbackLoadShippingMethods(Request $request, SalesChannelContext $context, Criteria $criteria): ShippingMethodRouteResponse
    {
        $searchIds = $criteria->getIds();

        if ($searchIds === []) {
            static::assertCount(1, $criteria->getFilters());

            $nand = $criteria->getFilters()[0];

            static::assertInstanceOf(NandFilter::class$nand);
            static::assertCount(1, $nand->getQueries());

            $nameFilter = $nand->getQueries()[0];

            static::assertInstanceOf(EqualsAnyFilter::class$nameFilter);

            $names = $nameFilter->getValue();

            
use KernelTestBehaviour;

    private ReplaceRecursiveFilter $replaceRecursiveFilter;

    protected function setUp(): void
    {
        $this->replaceRecursiveFilter = new ReplaceRecursiveFilter();
    }

    public function testGetFilterReturnsArrayWithTwigFilter(): void
    {
        $firstTwigFilter = $this->replaceRecursiveFilter->getFilters()[0];
        static::assertInstanceOf(TwigFilter::class$firstTwigFilter);
    }

    public function testIfFilterContainsReplaceRecursive(): void
    {
        $replaceRecursiveFilter = array_filter($this->replaceRecursiveFilter->getFilters()static fn ($filter) => $filter->getName() === 'replace_recursive');

        static::assertCount(1, $replaceRecursiveFilter);
    }

    public function testReplaceRecursiveTwoObjects(): void
    {
->create(Uuid::randomHex()$this->salesChannelId);

        $criteria = new Criteria();
        $criteria->addFilter(new ContainsFilter('name', 'Foo Bar'));

        $listing = $this->getContainer()
            ->get(ProductListingRoute::class)
            ->load($this->categoryStreamId, $request$context$criteria)
            ->getResult();

        static::assertSame(3, $listing->getTotal());
        $firstFilter = $listing->getCriteria()->getFilters()[0];
        static::assertInstanceOf(ContainsFilter::class$firstFilter);
        static::assertEquals('name', $firstFilter->getField());
        static::assertEquals('Foo Bar', $firstFilter->getValue());
    }

    public function testNotFilterableProperty(): void
    {
        $request = new Request();

        $context = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex()$this->salesChannelId);

        
private function handleCriteriaDelete(SyncOperation $operation, Context $context): void
    {
        $definition = $this->registry->getByEntityName($operation->getEntity());

        if (!$definition instanceof MappingEntityDefinition) {
            throw ApiException::invalidSyncCriteriaException($operation->getKey());
        }

        $criteria = $this->criteriaBuilder->fromArray(['filter' => $operation->getCriteria()]new Criteria()$definition$context);

        if (empty($criteria->getFilters())) {
            throw ApiException::invalidSyncCriteriaException($operation->getKey());
        }

        $ids = $this->searcher->search($definition$criteria$context);

        $operation->replacePayload(\array_values($ids->getIds()));
    }
}

                ['id' => $id, 'name' => 'Test', 'territory' => 'test', 'code' => 'test' . $id],
            ],
            $context
        );

        $criteria = new Criteria([$id]);
        $locale = $repository->search($criteria$context);

        static::assertEquals([$id]$criteria->getIds());
        static::assertEmpty($criteria->getSorting());
        static::assertEmpty($criteria->getFilters());
        static::assertEmpty($criteria->getPostFilters());
        static::assertEmpty($criteria->getAggregations());
        static::assertEmpty($criteria->getAssociations());
        static::assertNull($criteria->getLimit());
        static::assertNull($criteria->getOffset());

        static::assertCount(1, $locale);

        static::assertTrue($locale->has($id));
        $locale = $locale->get($id);
        static::assertInstanceOf(LocaleEntity::class$locale);
        
static::assertStringEqualsFile(
            __DIR__ . '/../_assertion/PluginListCommandTest-testCommand.txt',
            implode("\n", array_map('trim', explode("\n", trim($commandTester->getDisplay())))) . "\n"
        );
    }

    public function testFilter(): void
    {
        $filterValue = 'shopware-is-love';

        $criteria = static::callback(function DCriteria $criteria) use ($filterValue): bool {
            $filters = $criteria->getFilters();
            // must be MultiFilter             if (!(\count($filters) === 1 && $filters[0] instanceof MultiFilter)) {
                return false;
            }
            /** @var MultiFilter $filter */
            $filter = $filters[0];
            // must be OR             if ($filter->getOperator() !== MultiFilter::CONNECTION_OR) {
                return false;
            }
            $fields = ['name', 'label'];
            
Home | Imprint | This part of the site doesn't use cookies.