getDepth example


    public function arrayGetPath($array$glue = '.')
    {
        $result = [];
        $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
        foreach ($iterator as $leafValue) {
            $parts = [];
            foreach (range(0, $iterator->getDepth()) as $depth) {
                $parts[] = $iterator->getSubIterator($depth)->key();
            }

            $path = implode($glue$parts);

            $result[$path] = $leafValue;
        }

        return $result;
    }

    
$this->minDepth = $minDepth;
        $iterator->setMaxDepth(\PHP_INT_MAX === $maxDepth ? -1 : $maxDepth);

        parent::__construct($iterator);
    }

    /** * Filters the iterator values. */
    public function accept(): bool
    {
        return $this->getInnerIterator()->getDepth() >= $this->minDepth;
    }
}
 ?TreeFacetResult {
        $ids = $this->fetchCategoriesOfProducts($reverted$context);

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

        $ids = $this->filterSystemCategories($ids$context);

        $ids = $this->categoryDepthService->get(
            $context->getShop()->getCategory(),
            $facet->getDepth(),
            $ids
        );

        $categories = $this->categoryService->getList($ids$context);

        return $this->categoryTreeFacetResultBuilder->buildFacetResult(
            $categories,
            $this->getFilteredIds($criteria),
            $context->getShop()->getCategory()->getId(),
            $facet
        );
    }
return;
        }

        $categoryFacet = $criteria->getFacet('category');
        if (!$categoryFacet instanceof CategoryFacet) {
            return;
        }

        $ids = $this->filterSystemCategories($ids$context);
        $ids = $this->categoryDepthService->get(
            $context->getShop()->getCategory(),
            $categoryFacet->getDepth(),
            $ids
        );

        $categories = $this->categoryService->getList($ids$context);

        $facet = $this->categoryTreeFacetResultBuilder->buildFacetResult(
            $categories,
            $this->getFilteredIds($criteria),
            $context->getShop()->getCategory()->getId(),
            $categoryFacet
        );

        
continue;
                }

                $stack    = [&$pointer];
                $iterator = new RecursiveIteratorIterator(
                    new RecursiveArrayIterator($value),
                    RecursiveIteratorIterator::SELF_FIRST
                );

                foreach ($iterator as $key => $val) {
                    array_splice($stack$iterator->getDepth() + 1);
                    $pointer = &$stack[count($stack) - 1];
                    $pointer = &$pointer[$key];
                    $stack[] = &$pointer;

                    // RecursiveIteratorIterator::hasChildren() can be used. RecursiveIteratorIterator                     // forwards all unknown method calls to the underlying RecursiveIterator internally.                     // See https://github.com/php/doc-en/issues/787#issuecomment-881446121                     if ($iterator->hasChildren()) {
                        $pointer[$field] = $val;
                    }
                }
            }
Home | Imprint | This part of the site doesn't use cookies.