Mercurial > hg > isophonics-drupal-site
comparison vendor/phar-io/manifest/src/xml/ManifestElement.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | |
2 /* | |
3 * This file is part of PharIo\Manifest. | |
4 * | |
5 * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> | |
6 * | |
7 * For the full copyright and license information, please view the LICENSE | |
8 * file that was distributed with this source code. | |
9 */ | |
10 | |
11 namespace PharIo\Manifest; | |
12 | |
13 use DOMElement; | |
14 use DOMNodeList; | |
15 | |
16 class ManifestElement { | |
17 const XMLNS = 'https://phar.io/xml/manifest/1.0'; | |
18 | |
19 /** | |
20 * @var DOMElement | |
21 */ | |
22 private $element; | |
23 | |
24 /** | |
25 * ContainsElement constructor. | |
26 * | |
27 * @param DOMElement $element | |
28 */ | |
29 public function __construct(DOMElement $element) { | |
30 $this->element = $element; | |
31 } | |
32 | |
33 /** | |
34 * @param string $name | |
35 * | |
36 * @return string | |
37 * | |
38 * @throws ManifestElementException | |
39 */ | |
40 protected function getAttributeValue($name) { | |
41 if (!$this->element->hasAttribute($name)) { | |
42 throw new ManifestElementException( | |
43 sprintf( | |
44 'Attribute %s not set on element %s', | |
45 $name, | |
46 $this->element->localName | |
47 ) | |
48 ); | |
49 } | |
50 | |
51 return $this->element->getAttribute($name); | |
52 } | |
53 | |
54 /** | |
55 * @param $elementName | |
56 * | |
57 * @return DOMElement | |
58 * | |
59 * @throws ManifestElementException | |
60 */ | |
61 protected function getChildByName($elementName) { | |
62 $element = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0); | |
63 | |
64 if (!$element instanceof DOMElement) { | |
65 throw new ManifestElementException( | |
66 sprintf('Element %s missing', $elementName) | |
67 ); | |
68 } | |
69 | |
70 return $element; | |
71 } | |
72 | |
73 /** | |
74 * @param $elementName | |
75 * | |
76 * @return DOMNodeList | |
77 * | |
78 * @throws ManifestElementException | |
79 */ | |
80 protected function getChildrenByName($elementName) { | |
81 $elementList = $this->element->getElementsByTagNameNS(self::XMLNS, $elementName); | |
82 | |
83 if ($elementList->length === 0) { | |
84 throw new ManifestElementException( | |
85 sprintf('Element(s) %s missing', $elementName) | |
86 ); | |
87 } | |
88 | |
89 return $elementList; | |
90 } | |
91 | |
92 /** | |
93 * @param string $elementName | |
94 * | |
95 * @return bool | |
96 */ | |
97 protected function hasChild($elementName) { | |
98 return $this->element->getElementsByTagNameNS(self::XMLNS, $elementName)->length !== 0; | |
99 } | |
100 } |