hasChildren example

/** * Returns whether the current element of the iterator can be recursed * into. */
    public function hasChildren(): bool
    {
        return current($this->errors) instanceof self;
    }

    public function getChildren(): self
    {
        if (!$this->hasChildren()) {
            throw new LogicException(sprintf('The current element is not iterable. Use "%s" to get the current element.', self::class.'::current()'));
        }

        /** @var self $children */
        $children = current($this->errors);

        return $children;
    }

    /** * Returns the number of elements in the iterator. * * Note that this is not the total number of errors, if the constructor * parameter $deep was set to true! In that case, you should wrap the * iterator into a {@link \RecursiveIteratorIterator} with the standard mode * {@link \RecursiveIteratorIterator::LEAVES_ONLY} and count the result. * * $iterator = new \RecursiveIteratorIterator($form->getErrors(true)); * $count = count(iterator_to_array($iterator)); * * Alternatively, set the constructor argument $flatten to true as well. * * $count = count($form->getErrors(true, true)); */


                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;
                    }
                }
            }
        }

        return $output;
    }

    /** * Navigate through an array looking for a particular index * * @param array $index The index sequence we are navigating down * @param array $value The portion of the array to process * * @return UploadedFile|null */

    public function setQuantity(int $quantity): self
    {
        if ($quantity < 1) {
            throw CartException::invalidQuantity($quantity);
        }

        if (!$this->isStackable()) {
            throw CartException::lineItemNotStackable($this->id);
        }

        if ($this->hasChildren()) {
            $this->refreshChildQuantity($this->children, $this->quantity, $quantity);
        }

        if ($this->priceDefinition instanceof QuantityPriceDefinition) {
            $this->price = null;
        }

        $this->quantity = $quantity;

        return $this;
    }

    
$match = $filter->match(
                    new LineItemScope($lineItem$context)
                );

                return $match;
            }
        );
    }

    private function calculatePrice(LineItem $lineItem, SalesChannelContext $context, LineItemCollection $calculated, CartBehavior $behavior): CalculatedPrice
    {
        if ($lineItem->hasChildren()) {
            $children = $this->calculateLineItems($lineItem->getChildren()$context$behavior);

            $lineItem->setChildren($children);

            return $children->getPrices()->sum();
        }

        $definition = $lineItem->getPriceDefinition();

        if ($definition instanceof AbsolutePriceDefinition) {
            // reduce line items for provided filter
if (substr($namespace_prefix, -1) !== '\\') {
      throw new \InvalidArgumentException("Namespace prefix for $path must contain a trailing namespace separator.");
    }
    $flags = \FilesystemIterator::UNIX_PATHS;
    $flags |= \FilesystemIterator::SKIP_DOTS;
    $flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
    $flags |= \FilesystemIterator::CURRENT_AS_SELF;
    $flags |= \FilesystemIterator::KEY_AS_FILENAME;

    $iterator = new \RecursiveDirectoryIterator($path$flags);
    $filter = new \RecursiveCallbackFilterIterator($iteratorfunction D$current$file_name$iterator) {
      if ($iterator->hasChildren()) {
        return TRUE;
      }
      // We don't want to discover abstract TestBase classes, traits or       // interfaces. They can be deprecated and will call @trigger_error()       // during discovery.       return substr($file_name, -4) === '.php' &&
        substr($file_name, -12) !== 'TestBase.php' &&
        substr($file_name, -9) !== 'Trait.php' &&
        substr($file_name, -13) !== 'Interface.php';
    });
    $files = new \RecursiveIteratorIterator($filter);
    
$path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
            $path = str_replace('\\', '/', $path);

            return !preg_match($this->excludedPattern, $path);
        }

        return true;
    }

    public function hasChildren(): bool
    {
        return $this->isRecursive && $this->iterator->hasChildren();
    }

    public function getChildren(): self
    {
        $children = new self($this->iterator->getChildren()[]);
        $children->excludedDirs = $this->excludedDirs;
        $children->excludedPattern = $this->excludedPattern;

        return $children;
    }
}
'payload' => $lineItem->getPayload(),
            'states' => $lineItem->getStates(),
        ];

        $downloads = $lineItem->getExtensionOfType(OrderConverter::ORIGINAL_DOWNLOADS, OrderLineItemDownloadCollection::class);
        if ($downloads instanceof OrderLineItemDownloadCollection) {
            $data['downloads'] = array_values($downloads->map(fn (OrderLineItemDownloadEntity $download): array => ['id' => $download->getId()]));
        }

        $output[$lineItem->getId()] = array_filter($datafn ($value) => $value !== null);

        if ($lineItem->hasChildren()) {
            $output = [...$output, ...self::transformCollection($lineItem->getChildren()$id)];
        }

        return $output;
    }

    public static function transformFlatToNested(OrderLineItemCollection $lineItems): LineItemCollection
    {
        $lineItems->sortByPosition();
        $index = [];
        $root = new LineItemCollection();

        

        if (!$taxes) {
            return;
        }

        foreach ($lineItems as $lineItem) {
            if (!$lineItem->getPrice()) {
                throw CartException::missingLineItemPrice($lineItem->getUniqueIdentifier());
            }

            // trickle down for nested line items             if ($lineItem->hasChildren()) {
                $this->applyLineItemTaxes($lineItem->getChildren()$taxes);
            }

            // line item has no tax sum provided             if (!\array_key_exists($lineItem->getUniqueIdentifier()$taxes)) {
                continue;
            }

            // apply provided taxes             $tax = $taxes[$lineItem->getUniqueIdentifier()];
            $lineItem->getPrice()->setCalculatedTaxes($tax);
        }
$subPathname .= $this->getFilename();

        if ('/' !== $basePath = $this->rootPath) {
            $basePath .= $this->directorySeparator;
        }

        return new SplFileInfo($basePath.$subPathname$this->subPath, $subPathname);
    }

    public function hasChildren(bool $allowLinks = false): bool
    {
        $hasChildren = parent::hasChildren($allowLinks);

        if (!$hasChildren || !$this->ignoreUnreadableDirs) {
            return $hasChildren;
        }

        try {
            parent::getChildren();

            return true;
        } catch (\UnexpectedValueException) {
            // If directory is unreadable and finder is set to ignore it, skip children
Home | Imprint | This part of the site doesn't use cookies.