addChild example

$parentProfile->setIp('127.0.0.1');
        $parentProfile->setUrl('http://foo.bar/parent');
        $parentProfile->setStatusCode(200);
        $parentProfile->setMethod('GET');

        $childProfile = new Profile('token_child');
        $childProfile->setIp('127.0.0.1');
        $childProfile->setUrl('http://foo.bar/child');
        $childProfile->setStatusCode(200);
        $childProfile->setMethod('GET');

        $parentProfile->addChild($childProfile);

        $this->storage->write($parentProfile);
        $this->storage->write($childProfile);

        // Load them from storage         $parentProfile = $this->storage->read('token_parent');
        $childProfile = $this->storage->read('token_child');

        // Check child has link to parent         $this->assertNotNull($childProfile->getParent());
        $this->assertEquals($parentProfile->getToken()$childProfile->getParentToken());

        
/** * @param array<string, mixed> $payload */
    private static function payloadItem(string $id, array $payload): LineItem
    {
        $item = new LineItem($id, 'foo');
        $item->setPayload($payload);

        $childItem = new LineItem($id . '-child', 'foo');
        $childItem->setPayload($payload);

        $item->addChild($childItem);

        return $item;
    }

    private static function coverItem(string $id, ?string $thumbnailString, bool $skipCover = false): LineItem
    {
        $item = new LineItem($id, 'foo');
        $childItem = new LineItem($id . 'child', 'foo');

        $item->addChild($childItem);

        
if (!$parent && $data['parent']) {
            $parent = $this->read($data['parent']);
        }

        if ($parent) {
            $profile->setParent($parent);
        }

        foreach ($data['children'] as $token) {
            if (null !== $childProfile = $this->doRead($token$profile)) {
                $profile->addChild($childProfile);
            }
        }

        return $profile;
    }

    private function doRead($token, Profile $profile = null): ?Profile
    {
        if (!$token || !file_exists($file = $this->getFilename($token))) {
            return null;
        }

        
$prototype = new ArrayNode(null, $node);
        $node->setPrototype($prototype);
        $node->setDefaultValue(['test']);
        $this->assertEquals(['test']$node->getDefaultValue());
    }

    // a remapped key (e.g. "mapping" -> "mappings") should be unset after being used     public function testRemappedKeysAreUnset()
    {
        $node = new ArrayNode('root');
        $mappingsNode = new PrototypedArrayNode('mappings');
        $node->addChild($mappingsNode);

        // each item under mappings is just a scalar         $prototype = new ScalarNode(null, $mappingsNode);
        $mappingsNode->setPrototype($prototype);

        $remappings = [];
        $remappings[] = ['mapping', 'mappings'];
        $node->setXmlRemappings($remappings);

        $normalized = $node->normalize(['mapping' => ['foo', 'bar']]);
        $this->assertEquals(['mappings' => ['foo', 'bar']]$normalized);
    }
if ( null === $node ) {
        $node = new SimpleXMLElement( '<oembed></oembed>' );
    }

    foreach ( $data as $key => $value ) {
        if ( is_numeric( $key ) ) {
            $key = 'oembed';
        }

        if ( is_array( $value ) ) {
            $item = $node->addChild( $key );
            _oembed_create_xml( $value$item );
        } else {
            $node->addChild( $keyesc_html( $value ) );
        }
    }

    return $node->asXML();
}

/** * Filters the given oEmbed HTML to make sure iframes have a title attribute. * * @since 5.2.0 * * @param string $result The oEmbed HTML result. * @param object $data A data object result from an oEmbed provider. * @param string $url The URL of the content to be embedded. * @return string The filtered oEmbed result. */

        $childNode = new ScalarNode('foo');
        $childNode->setDeprecated('vendor/package', '1.1', '"%node%" is deprecated');

        $this->assertTrue($childNode->isDeprecated());
        $deprecation = $childNode->getDeprecation($childNode->getName()$childNode->getPath());
        $this->assertSame('"foo" is deprecated', $deprecation['message']);
        $this->assertSame('vendor/package', $deprecation['package']);
        $this->assertSame('1.1', $deprecation['version']);

        $node = new ArrayNode('root');
        $node->addChild($childNode);

        $deprecationTriggered = 0;
        $deprecationHandler = function D$level$message$file$line) use (&$prevErrorHandler, &$deprecationTriggered) {
            if (\E_USER_DEPRECATED === $level) {
                return ++$deprecationTriggered;
            }

            return $prevErrorHandler ? $prevErrorHandler($level$message$file$line) : false;
        };

        $prevErrorHandler = set_error_handler($deprecationHandler);
        

    public function render()
    {
        $xml         = new SimpleXMLElement('<zend-config xmlns:zf="' . Zend_Config_Xml::XML_NAMESPACE . '"/>');
        $extends     = $this->_config->getExtends();
        $sectionName = $this->_config->getSectionName();

        if (is_string($sectionName)) {
            $child = $xml->addChild($sectionName);

            $this->_addBranch($this->_config, $child$xml);
        } else {
            foreach ($this->_config as $sectionName => $data) {
                if (!($data instanceof Zend_Config)) {
                    $xml->addChild($sectionName(string) $data);
                } else {
                    $child = $xml->addChild($sectionName);

                    if (isset($extends[$sectionName])) {
                        $child->addAttribute('zf:extends', $extends[$sectionName], Zend_Config_Xml::XML_NAMESPACE);
                    }
false,
        ];

        yield 'Reference id with gte operator' => [
            new LineItem($ids->get('line-item-id'), LineItem::PRODUCT_LINE_ITEM_TYPE, $ids->get('reference-id'), 4),
            new LineItemWithQuantityRule(Rule::OPERATOR_GTE, $ids->get('reference-id'), 3),
            true,
        ];

        yield 'Nested line item should be considered' => [
            (new LineItem($ids->get('line-item-id'), LineItem::PRODUCT_LINE_ITEM_TYPE, $ids->get('container-id'), 1))
                ->addChild(new LineItem($ids->get('line-item-id'), LineItem::PRODUCT_LINE_ITEM_TYPE, $ids->get('reference-id'), 1)),
            new LineItemWithQuantityRule(Rule::OPERATOR_EQ, $ids->get('reference-id'), 1),
            true,
        ];
    }
}
new CalculatedTax(
                    38,
                    19,
                    200
                ),
            ]),
            new TaxRuleCollection(),
            1
        );

        $lineItemChild->setPrice(clone $price);
        $lineItemChild->addChild($lineItemGrandChild1);
        $lineItemChild->addChild($lineItemGrandChild2);

        $cart = $this->createCart();
        $cart->setDeliveries(new DeliveryCollection());

        $lineItem = $cart->get($this->ids->get('line-item-1'));

        static::assertNotNull($lineItem);

        // 238 > 238 > 119 + 119         // line-item 1 > line-item-2 > (line-item-3 && line-item-4)
if ($prototype instanceof ArrayNode) {
            $keyNode = new ArrayNode($key$node);
            $children = $prototype->getChildren();

            if ($prototype instanceof PrototypedArrayNode && $prototype->getKeyAttribute()) {
                $children = $this->getPrototypeChildren($prototype);
            }

            // add children             foreach ($children as $childNode) {
                $keyNode->addChild($childNode);
            }
        } else {
            $keyNode = new ScalarNode($key$node);
        }

        $info = 'Prototype';
        if (null !== $prototype->getInfo()) {
            $info .= ': '.$prototype->getInfo();
        }
        $keyNode->setInfo($info);

        
$parentItem = $lineItems->get($lineItem->getParentId());
                if ($parentItem === null) {
                    continue;
                }

                // NEXT-21735 - This is covered randomly                 // @codeCoverageIgnoreStart                 $index[$lineItem->getParentId()] = self::createLineItem($parentItem);
                // @codeCoverageIgnoreEnd             }

            $index[$lineItem->getParentId()]->addChild($currentLineItem);
        }

        return $root;
    }

    private static function updateLineItem(LineItem $lineItem, OrderLineItemEntity $entity, string $id): void
    {
        $lineItem->setId($entity->getIdentifier())
            ->setLabel($entity->getLabel())
            ->setGood($entity->getGood())
            ->setRemovable($entity->getRemovable())
            
/** * Sets children profiler. * * @param Profile[] $children * * @return void */
    public function setChildren(array $children)
    {
        $this->children = [];
        foreach ($children as $child) {
            $this->addChild($child);
        }
    }

    /** * Adds the child token. * * @return void */
    public function addChild(self $child)
    {
        $this->children[] = $child;
        
        $this->enterNode($nodeName$domNode$cursor);
        $this->visitChildren($domNode$cursor);
        $cursor->node = $cursor->node->getParent();
    }

    private function enterNode(string $domNodeName, \DOMNode $domNode, Cursor $cursor): void
    {
        // Element should be blocked, retaining its children         if (false === $this->elementsConfig[$domNodeName]) {
            $node = new BlockedNode($cursor->node);

            $cursor->node->addChild($node);
            $cursor->node = $node;

            return;
        }

        // Otherwise create the node         $node = new Node($cursor->node, $domNodeName);
        $this->setAttributes($domNodeName$domNode$node$this->elementsConfig[$domNodeName]);

        // Force configured attributes         foreach ($this->forcedAttributes[$domNodeName] ?? [] as $attribute => $value) {
            
public function get_sitemap_index_xml( $sitemaps ) {
        $sitemap_index = new SimpleXMLElement(
            sprintf(
                '%1$s%2$s%3$s',
                '<?xml version="1.0" encoding="UTF-8" ?>',
                $this->stylesheet_index,
                '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />'
            )
        );

        foreach ( $sitemaps as $entry ) {
            $sitemap = $sitemap_index->addChild( 'sitemap' );

            // Add each element as a child node to the <sitemap> entry.             foreach ( $entry as $name => $value ) {
                if ( 'loc' === $name ) {
                    $sitemap->addChild( $nameesc_url( $value ) );
                } elseif ( 'lastmod' === $name ) {
                    $sitemap->addChild( $nameesc_xml( $value ) );
                } else {
                    _doing_it_wrong(
                        __METHOD__,
                        sprintf(
                            

    protected function arrayToXML(array $data, &$output)
    {
        foreach ($data as $key => $value) {
            $key = $this->normalizeXMLTag($key);

            if (is_array($value)) {
                $subnode = $output->addChild("{$key}");
                $this->arrayToXML($value$subnode);
            } else {
                $output->addChild("{$key}", htmlspecialchars("{$value}"));
            }
        }
    }

    /** * Normalizes tags into the allowed by W3C. * Regex adopted from this StackOverflow answer. * * @param int|string $key * * @return string * * @see https://stackoverflow.com/questions/60001029/invalid-characters-in-xml-tag-name */
Home | Imprint | This part of the site doesn't use cookies.