filter example

    $this->drupalGet('theme-test/suggestion-alter');
    // Ensure that the order is first by extension, then for a given extension,     // the hook-specific one after the generic one.     $expected_order = [
      'theme_suggestions_test_theme_suggestions_alter() executed.',
      'theme_suggestions_test_theme_suggestions_theme_test_suggestions_alter() executed.',
      'theme_test_theme_suggestions_alter() executed for theme_test_suggestions.',
      'theme_test_theme_suggestions_theme_test_suggestions_alter() executed.',
      'test_theme_theme_suggestions_alter() executed.',
      'test_theme_theme_suggestions_theme_test_suggestions_alter() executed.',
    ];
    $content = preg_replace('/\s+/', ' ', Xss::filter($this->getSession()->getPage()->getContent()[]));
    $order = 0;
    foreach ($expected_order as $expected_string) {
      $this->assertGreaterThan($orderstrpos($content$expected_string));
      $order = strpos($content$expected_string);
    }
  }

}
$documentIds[] = $delivery->getId();

        static::assertCount(2, $documentIds);

        $criteria = new Criteria($documentIds);
        $criteria->addAssociation('documentType');

        $documents = $this->documentRepository->search($criteria$this->context);

        static::assertCount(2, $documents);

        $invoiceDoc = $documents->filter(function DDocumentEntity $doc) {
            static::assertNotNull($doc->getDocumentType());

            return $doc->getDocumentType()->getTechnicalName() === InvoiceRenderer::TYPE;
        })->first();

        static::assertNotNull($invoiceDoc);
        static::assertInstanceOf(DocumentEntity::class$invoiceDoc);
        static::assertSame($orderId$invoiceDoc->getOrderId());
        static::assertSame(FileTypes::PDF, $invoiceDoc->getFileType());

        $deliveryDoc = $documents->filter(function DDocumentEntity $doc) {
            
foreach ($lineItems as $lineItem) {
            if ($lineItem->getType() === $type) {
                $filtered[] = $lineItem;
            }
        }

        return $filtered;
    }

    public function filterType(string $type): LineItemCollection
    {
        return $this->filter(
            fn (LineItem $lineItem) => $lineItem->getType() === $type
        );
    }

    public function hasLineItemWithState(string $state): bool
    {
        foreach ($this->buildFlat($this) as $lineItem) {
            if (\in_array($state$lineItem->getStates(), true)) {
                return true;
            }
        }

        

    /** * @return list<string> */
    public function getNumberRangeTypeIds(): array
    {
        return $this->fmap(fn (NumberRangeTypeTranslationEntity $numberRangeTypeTranslation) => $numberRangeTypeTranslation->getNumberRangeTypeId());
    }

    public function filterByNumberRangeTypeId(string $id): self
    {
        return $this->filter(fn (NumberRangeTypeTranslationEntity $numberRangeTypeTranslation) => $numberRangeTypeTranslation->getNumberRangeTypeId() === $id);
    }

    /** * @return list<string> */
    public function getLanguageIds(): array
    {
        return $this->fmap(fn (NumberRangeTypeTranslationEntity $numberRangeTypeTranslation) => $numberRangeTypeTranslation->getLanguageId());
    }

    public function filterByLanguageId(string $id): self
    {
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
    {
        
$parentDefinition = $parent['definition'];

        $definition = $child['definition'];
        if ($association instanceof ManyToManyAssociationField) {
            $definition = $association->getToManyReferenceDefinition();
        }

        $criteria = $this->criteriaBuilder->handleRequest($request$criteria$definition$context);

        if ($association instanceof ManyToManyAssociationField) {
            // fetch inverse association definition for filter             $reverses = $definition->getFields()->filter(
                fn (Field $field) => $field instanceof ManyToManyAssociationField && $association->getMappingDefinition() === $field->getMappingDefinition()
            );

            // contains now the inverse side association: category.products             /** @var ManyToManyAssociationField|null $reverse */
            $reverse = $reverses->first();
            if (!$reverse) {
                throw ApiException::missingReverseAssociation($definition->getEntityName()$parentDefinition->getEntityName());
            }

            $criteria->addFilter(
                
private readonly Connection $connection,
        private readonly TokenizerInterface $tokenizer,
        private readonly LoggerInterface $logger,
        private readonly AbstractTokenFilter $tokenFilter
    ) {
    }

    public function interpret(string $word, Context $context): SearchPattern
    {
        $tokens = $this->tokenizer->tokenize($word);

        $tokens = $this->tokenFilter->filter($tokens$context);

        if (empty($tokens)) {
            return new SearchPattern(new SearchTerm(''));
        }

        $tokenSlops = $this->slop($tokens);
        if (!$this->checkSlops(array_values($tokenSlops))) {
            return new SearchPattern(new SearchTerm($word));
        }

        $tokenKeywords = $this->fetchKeywords($context$tokenSlops);
        

    /** * @return list<string> */
    public function getSalesChannelTypeIds(): array
    {
        return $this->fmap(fn (SalesChannelTypeTranslationEntity $salesChannelTypeTranslation) => $salesChannelTypeTranslation->getSalesChannelTypeId());
    }

    public function filterBySalesChannelId(string $id): self
    {
        return $this->filter(fn (SalesChannelTypeTranslationEntity $salesChannelTypeTranslation) => $salesChannelTypeTranslation->getSalesChannelTypeId() === $id);
    }

    /** * @return list<string> */
    public function getLanguageIds(): array
    {
        return $this->fmap(fn (SalesChannelTypeTranslationEntity $salesChannelTranslation) => $salesChannelTranslation->getLanguageId());
    }

    public function filterByLanguageId(string $id): self
    {
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\Log\Package;

/** * @extends EntityCollection<OrderLineItemDownloadEntity> */
#[Package('checkout')] class OrderLineItemDownloadCollection extends EntityCollection
{
    public function filterByOrderLineItemId(string $id): self
    {
        return $this->filter(fn (OrderLineItemDownloadEntity $orderLineItemDownloadEntity) => $orderLineItemDownloadEntity->getOrderLineItemId() === $id);
    }

    public function getApiAlias(): string
    {
        return 'order_line_item_download_collection';
    }

    protected function getExpectedClass(): string
    {
        return OrderLineItemDownloadEntity::class;
    }
}

    public function update(string $entity, array $ids, Context $context): void
    {
        $ids = array_unique(array_filter($ids));
        if (empty($ids)) {
            return;
        }

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

        $inherited = $definition->getFields()->filter(fn (Field $field) => $field->is(Inherited::class) && $field instanceof AssociationField);

        $associations = $inherited->filter(fn (Field $field) => $field instanceof OneToManyAssociationField || $field instanceof ManyToManyAssociationField || $field instanceof OneToOneAssociationField);

        if ($associations->count() > 0) {
            $this->updateToManyAssociations($definition$ids$associations$context);
        }

        $associations = $inherited->filter(fn (Field $field) => $field instanceof ManyToOneAssociationField);

        if ($associations->count() > 0) {
            $this->updateToOneAssociations($definition$ids$associations$context);
        }

    $_term = apply_filters( "get_{$taxonomy}", $_term$taxonomy );

    // Bail if a filter callback has changed the type of the `$_term` object.     if ( ! ( $_term instanceof WP_Term ) ) {
        return $_term;
    }

    // Sanitize term, according to the specified filter.     $_term->filter( $filter );

    if ( ARRAY_A === $output ) {
        return $_term->to_array();
    } elseif ( ARRAY_N === $output ) {
        return array_values( $_term->to_array() );
    }

    return $_term;
}

/** * Gets all term data from database by term field and data. * * Warning: $value is not escaped for 'name' $field. You must do it yourself, if * required. * * The default $field is 'id', therefore it is possible to also use null for * field, but not recommended that you do so. * * If $value does not exist, the return value will be false. If $taxonomy exists * and $field and $value combinations exist, the term will be returned. * * This function will always return the first term that matches the `$field`- * `$value`-`$taxonomy` combination specified in the parameters. If your query * is likely to match more than one term (as is likely to be the case when * `$field` is 'name', for example), consider using get_terms() instead; that * way, you will get all matching terms, and can provide your own logic for * deciding which one was intended. * * @todo Better formatting for DocBlock. * * @since 2.3.0 * @since 4.4.0 `$taxonomy` is optional if `$field` is 'term_taxonomy_id'. Converted to return * a WP_Term object if `$output` is `OBJECT`. * @since 5.5.0 Added 'ID' as an alias of 'id' for the `$field` parameter. * * @see sanitize_term_field() The $context param lists the available values for get_term_by() $filter param. * * @param string $field Either 'slug', 'name', 'term_id' (or 'id', 'ID'), or 'term_taxonomy_id'. * @param string|int $value Search for this term value. * @param string $taxonomy Taxonomy name. Optional, if `$field` is 'term_taxonomy_id'. * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which * correspond to a WP_Term object, an associative array, or a numeric array, * respectively. Default OBJECT. * @param string $filter Optional. How to sanitize term fields. Default 'raw'. * @return WP_Term|array|false WP_Term instance (or array) on success, depending on the `$output` value. * False if `$taxonomy` does not exist or `$term` was not found. */
public function match(RuleScope $scope): bool
    {
        if (!$scope instanceof CartRuleScope) {
            return false;
        }

        $promotions = new LineItemCollection($scope->getCart()->getLineItems()->filterFlatByType(LineItem::PROMOTION_LINE_ITEM_TYPE));
        $filter = $this->filter;
        if ($filter !== null) {
            $context = $scope->getSalesChannelContext();

            $promotions = $promotions->filter(static function DLineItem $lineItem) use ($filter$context) {
                $scope = new LineItemScope($lineItem$context);

                return $filter->match($scope);
            });
        }

        $promotionAmount = $promotions->getPrices()->sum()->getTotalPrice() * -1;

        return RuleComparison::numeric($promotionAmount$this->amount, $this->operator);
    }

    

  public static function filterAdmin($string) {
    return static::filter($stringstatic::$adminTags);
  }

  /** * Processes an HTML tag. * * @param string $string * The HTML tag to process. * @param array $html_tags * An array where the keys are the allowed tags and the values are not * used. * @param string $class * The called class. This method is called from an anonymous function which * breaks late static binding. See https://bugs.php.net/bug.php?id=66622 for * more information. * * @return string * If the element isn't allowed, an empty string. Otherwise, the cleaned up * version of the HTML element. */
public function toString(): string
    {
        return sprintf('has a node matching selector "%s" with content "%s"', $this->selector, $this->expectedText);
    }

    /** * @param Crawler $crawler */
    protected function matches($crawler): bool
    {
        $crawler = $crawler->filter($this->selector);
        if (!\count($crawler)) {
            return false;
        }

        return $this->expectedText === trim($crawler->text(null, true));
    }

    /** * @param Crawler $crawler */
    protected function failureDescription($crawler): string
    {
$this->criteria = $criteria;
        $this->context = $context;
        $this->aggregations = $aggregations ?? new AggregationResultCollection();
        $this->limit = $criteria->getLimit();
        $this->page = !$criteria->getLimit() ? 1 : (int) ceil((($criteria->getOffset() ?? 0) + 1) / $criteria->getLimit());

        parent::__construct($entities);
    }

    public function filter(\Closure $closure)
    {
        return $this->createNew($this->entities->filter($closure));
    }

    public function slice(int $offset, ?int $length = null)
    {
        return $this->createNew($this->entities->slice($offset$length));
    }

    public function getTotal(): int
    {
        return $this->total;
    }

    
Home | Imprint | This part of the site doesn't use cookies.