<?php declare(strict_types = 1); /* * This file is part of PharIo\Manifest. * * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Manifest; use DOMElement; use DOMNodeList; class ManifestElement { public const XMLNS = 'https://phar.io/xml/manifest/1.0'; /** @var DOMElement */ private $element; public function __construct(DOMElement $element) { $this->element = $element; } protected function getAttributeValue(string $name): string { if (!$this->element->hasAttribute($name)) { throw new ManifestElementException( \sprintf( 'Attribute %s not set on element %s', $name, $this->element->localName ) ); } return $this->element->getAttribute($name); } protected function getChildByName(string $elementName): DOMElement { $element = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0); if (!$element instanceof DOMElement) { throw new ManifestElementException( \sprintf('Element %s missing', $elementName) ); } return $element; } protected function getChildrenByName(string $elementName): DOMNodeList { $elementList = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName); if ($elementList->length === 0) { throw new ManifestElementException( \sprintf('Element(s) %s missing', $elementName) ); } return $elementList; } protected function hasChild(string $elementName): bool { return $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->length !== 0; } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
AuthorElement.php | File | 629 B | 0644 |
|
AuthorElementCollection.php | File | 583 B | 0644 |
|
BundlesElement.php | File | 622 B | 0644 |
|
ComponentElement.php | File | 636 B | 0644 |
|
ComponentElementCollection.php | File | 592 B | 0644 |
|
ContainsElement.php | File | 905 B | 0644 |
|
CopyrightElement.php | File | 774 B | 0644 |
|
ElementCollection.php | File | 1.58 KB | 0644 |
|
ExtElement.php | File | 524 B | 0644 |
|
ExtElementCollection.php | File | 574 B | 0644 |
|
ExtensionElement.php | File | 640 B | 0644 |
|
LicenseElement.php | File | 626 B | 0644 |
|
ManifestDocument.php | File | 2.99 KB | 0644 |
|
ManifestElement.php | File | 2.01 KB | 0644 |
|
PhpElement.php | File | 795 B | 0644 |
|
RequiresElement.php | File | 575 B | 0644 |
|