fromXml example


    public function testFromXml(): void
    {
        $document = XmlUtils::loadFile(
            __DIR__ . '/../../../_fixtures/Resources/flow-action.xml',
            __DIR__ . '/../../../../../../../../src/Core/Framework/App/FlowAction/Schema/flow-action-1.0.xsd'
        );

        /** @var \DOMElement $actions */
        $actions = $document->getElementsByTagName('flow-actions')->item(0);

        $action = Actions::fromXml($actions);
        static::assertCount(1, $action->getActions());
        static::assertInstanceOf(Action::class$action->getActions()[0]);
    }
}
$childElementLicense = $domDocument->createElement('license', 'license value');
        $childElementVersion = $domDocument->createElement('version', 'version value');

        $domElement->appendChild($childElementLabel);
        $domElement->appendChild($childElementName);
        $domElement->appendChild($childElementUrl);
        $domElement->appendChild($childElementAuthor);
        $domElement->appendChild($childElementCopyright);
        $domElement->appendChild($childElementLicense);
        $domElement->appendChild($childElementVersion);

        $metaData = Metadata::fromXml($domElement);

        $manifestConstructor->invoke(
            $manifest,
            'foo',
            $metaData,
            null,
            null,
            null,
            null,
            null,
            null,
            
public static function createFromXmlFile(string $xmlFilePath): self
    {
        try {
            $doc = XmlUtils::loadFile($xmlFilePath, self::XSD_FILEPATH);
        } catch (\Exception $e) {
            throw new XmlParsingException($xmlFilePath$e->getMessage());
        }

        /** @var \DOMElement $domItem */
        $domItem = $doc->getElementsByTagName('admin-ui')->item(0);

        return new self(AdminUi::fromXml($domItem));
    }

    public function getAdminUi(): ?AdminUi
    {
        return $this->adminUi;
    }
}
return ['swag.before.open_the_doors' => Uuid::fromHexToBytes($appId)];
        });

        $flowEventMock = $this->createMock(Event::class);
        $domDocument = new \DOMDocument();
        $domElement = $domDocument->createElement('root');
        $childElementLabel = $domDocument->createElement('flow-event', 'value');
        $childElementLabel->appendChild($domDocument->createElement('name', 'value'));
        $domElement->appendChild($childElementLabel);

        $customEventsMock = CustomEvents::fromXml($domElement);
        $flowEventMock->method('getCustomEvents')->willReturn($customEventsMock);

        $this->flowEventsRepositoryMock->expects(static::once())->method('upsert')->willReturnCallback(function D$upserts$context) use ($appId): EntityWrittenContainerEvent {
            static::assertSame([
                [
                    'appId' => $appId,
                    'name' => 'value',
                    'aware' => [],
                ],
            ]$upserts);

            
$adminUiEntityElement->setAttribute('name', 'AdminUiTest');
        $adminUiEntityElement->setAttribute('icon', 'triangle');
        $adminUiEntityElement->setAttribute('color', 'red');
        $adminUiEntityElement->setAttribute('position', '1');
        $adminUiEntityElement->setAttribute('navigation-parent', 'test');

        $adminUiElement->appendChild(
            $adminUiEntityElement
        );

        $adminUi = AdminUi::fromXml($adminUiElement);

        $adminUiEntities = $adminUi->getEntities();
        static::assertInstanceOf(AdminUi::class$adminUi);
        static::assertIsArray($adminUiEntities);
        static::assertInstanceOf(AdminUiEntity::class, \array_pop($adminUiEntities));
    }
}

#[Package('content')] final class Detail extends ConfigXmlElement
{
    private function __construct(
        protected readonly Tabs $tabs
    ) {
    }

    public static function fromXml(\DOMElement $element): self
    {
        return new self(Tabs::fromXml($element));
    }

    public function getTabs(): Tabs
    {
        return $this->tabs;
    }
}
return json_decode($parameters, true, 512, \JSON_THROW_ON_ERROR);
    }

    /** * @return array<string, mixed> */
    private static function parse(\DOMElement $element): array
    {
        $values = [];

        foreach ($element->getElementsByTagName('meta') as $meta) {
            $values['meta'] = Metadata::fromXml($meta);
        }

        foreach ($element->getElementsByTagName('headers') as $header) {
            $values['headers'] = Headers::fromXml($header);
        }

        foreach ($element->getElementsByTagName('parameters') as $parameter) {
            $values['parameters'] = Parameters::fromXml($parameter);
        }

        foreach ($element->getElementsByTagName('config') as $config) {
            
return new self(self::parseParameter($element));
    }

    /** * @return array<int, Parameter> */
    private static function parseParameter(\DOMElement $element): array
    {
        $values = [];

        foreach ($element->getElementsByTagName('parameter') as $parameter) {
            $values[] = Parameter::fromXml($parameter);
        }

        return $values;
    }
}
protected readonly string $name,
        protected readonly string $icon,
        protected readonly string $color,
        protected readonly int $position,
        protected readonly string $navigationParent,
    ) {
    }

    public static function fromXml(\DOMElement $element): self
    {
        return new self(
            Listing::fromXml($element),
            Detail::fromXml($element),
            XmlUtils::phpize($element->getAttribute('name')),
            XmlUtils::phpize($element->getAttribute('icon')),
            XmlUtils::phpize($element->getAttribute('color')),
            XmlUtils::phpize($element->getAttribute('position')),
            XmlUtils::phpize($element->getAttribute('navigation-parent')),
        );
    }

    public function getDetail(): Detail
    {
        
class CustomEventsTest extends TestCase
{
    public function testFromXml(): void
    {
        $doc = XmlUtils::loadFile(
            __DIR__ . '/../../../_fixtures/Resources/flow.xml',
            __DIR__ . '/../../../../../../../../src/Core/Framework/App/Flow/Schema/flow-1.0.xsd'
        );

        /** @var \DOMElement $events */
        $events = $doc->getElementsByTagName('flow-events')->item(0);
        $result = CustomEvents::fromXml($events)->toArray('en-GB');
        static::assertArrayHasKey('customEvent', $result);
    }
}

    public function testFromXml(): void
    {
        $dom = new \DOMDocument();
        $detailElement = $dom->createElement('detail');
        $tabsElement = $dom->createElement('tabs');

        $detailElement->appendChild(
            $tabsElement
        );

        $detail = Detail::fromXml($detailElement);
        static::assertInstanceOf(Detail::class$detail);

        $tabs = $detail->getTabs();
        static::assertInstanceOf(Tabs::class$tabs);
    }
}

        $dom = new \DOMDocument();
        $cardElement = $dom->createElement('card');
        $cardElement->setAttribute('name', 'CardTest');

        $cardFieldElement = $dom->createElement('field');

        $cardElement->appendChild(
            $cardFieldElement
        );

        $card = Card::fromXml($cardElement);

        $cardFields = $card->getFields();
        static::assertInstanceOf(Card::class$card);
        static::assertIsArray($cardFields);
        static::assertInstanceOf(CardField::class, \array_pop($cardFields));
    }
}
$parameters = $action->getElementsByTagName('parameters')->item(0);

        /** @var \DOMElement $parameter */
        $parameter = $parameters->getElementsByTagName('parameter')->item(0);

        $expected = [
            'type' => 'string',
            'name' => 'to',
            'value' => '{{ customer.name }}',
        ];

        $result = Parameter::fromXml($parameter);
        static::assertCount(3, $result->toArray('en-GB'));
        static::assertEquals($expected$result->toArray('en-GB'));
    }
}
return new self(self::parseInputField($element));
    }

    /** * @return array<int, InputField> */
    private static function parseInputField(\DOMElement $element): array
    {
        $values = [];

        foreach ($element->getElementsByTagName('input-field') as $parameter) {
            $values[] = InputField::fromXml($parameter);
        }

        return $values;
    }
}

        return $this->actions;
    }

    /** * @return array<int, Action> */
    private static function parseFlowActions(\DOMElement $element): array
    {
        $actions = [];
        foreach ($element->getElementsByTagName('flow-action') as $flowAction) {
            $actions[] = Action::fromXml($flowAction);
        }

        return $actions;
    }
}
Home | Imprint | This part of the site doesn't use cookies.