first commit
This commit is contained in:
25
vendor/phar-io/manifest/src/xml/AuthorElement.php
vendored
Normal file
25
vendor/phar-io/manifest/src/xml/AuthorElement.php
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class AuthorElement extends ManifestElement {
|
||||
public function getName(): string {
|
||||
return $this->getAttributeValue('name');
|
||||
}
|
||||
|
||||
public function getEmail(): string {
|
||||
return $this->getAttributeValue('email');
|
||||
}
|
||||
|
||||
public function hasEMail(): bool {
|
||||
return $this->hasAttribute('email');
|
||||
}
|
||||
}
|
||||
19
vendor/phar-io/manifest/src/xml/AuthorElementCollection.php
vendored
Normal file
19
vendor/phar-io/manifest/src/xml/AuthorElementCollection.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class AuthorElementCollection extends ElementCollection {
|
||||
public function current(): AuthorElement {
|
||||
return new AuthorElement(
|
||||
$this->getCurrentElement()
|
||||
);
|
||||
}
|
||||
}
|
||||
19
vendor/phar-io/manifest/src/xml/BundlesElement.php
vendored
Normal file
19
vendor/phar-io/manifest/src/xml/BundlesElement.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class BundlesElement extends ManifestElement {
|
||||
public function getComponentElements(): ComponentElementCollection {
|
||||
return new ComponentElementCollection(
|
||||
$this->getChildrenByName('component')
|
||||
);
|
||||
}
|
||||
}
|
||||
21
vendor/phar-io/manifest/src/xml/ComponentElement.php
vendored
Normal file
21
vendor/phar-io/manifest/src/xml/ComponentElement.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class ComponentElement extends ManifestElement {
|
||||
public function getName(): string {
|
||||
return $this->getAttributeValue('name');
|
||||
}
|
||||
|
||||
public function getVersion(): string {
|
||||
return $this->getAttributeValue('version');
|
||||
}
|
||||
}
|
||||
19
vendor/phar-io/manifest/src/xml/ComponentElementCollection.php
vendored
Normal file
19
vendor/phar-io/manifest/src/xml/ComponentElementCollection.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class ComponentElementCollection extends ElementCollection {
|
||||
public function current(): ComponentElement {
|
||||
return new ComponentElement(
|
||||
$this->getCurrentElement()
|
||||
);
|
||||
}
|
||||
}
|
||||
31
vendor/phar-io/manifest/src/xml/ContainsElement.php
vendored
Normal file
31
vendor/phar-io/manifest/src/xml/ContainsElement.php
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class ContainsElement extends ManifestElement {
|
||||
public function getName(): string {
|
||||
return $this->getAttributeValue('name');
|
||||
}
|
||||
|
||||
public function getVersion(): string {
|
||||
return $this->getAttributeValue('version');
|
||||
}
|
||||
|
||||
public function getType(): string {
|
||||
return $this->getAttributeValue('type');
|
||||
}
|
||||
|
||||
public function getExtensionElement(): ExtensionElement {
|
||||
return new ExtensionElement(
|
||||
$this->getChildByName('extension')
|
||||
);
|
||||
}
|
||||
}
|
||||
25
vendor/phar-io/manifest/src/xml/CopyrightElement.php
vendored
Normal file
25
vendor/phar-io/manifest/src/xml/CopyrightElement.php
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class CopyrightElement extends ManifestElement {
|
||||
public function getAuthorElements(): AuthorElementCollection {
|
||||
return new AuthorElementCollection(
|
||||
$this->getChildrenByName('author')
|
||||
);
|
||||
}
|
||||
|
||||
public function getLicenseElement(): LicenseElement {
|
||||
return new LicenseElement(
|
||||
$this->getChildByName('license')
|
||||
);
|
||||
}
|
||||
}
|
||||
68
vendor/phar-io/manifest/src/xml/ElementCollection.php
vendored
Normal file
68
vendor/phar-io/manifest/src/xml/ElementCollection.php
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* 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;
|
||||
use Iterator;
|
||||
use ReturnTypeWillChange;
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function sprintf;
|
||||
|
||||
/** @template-implements Iterator<int,DOMElement> */
|
||||
abstract class ElementCollection implements Iterator {
|
||||
/** @var DOMElement[] */
|
||||
private $nodes = [];
|
||||
|
||||
/** @var int */
|
||||
private $position;
|
||||
|
||||
public function __construct(DOMNodeList $nodeList) {
|
||||
$this->position = 0;
|
||||
$this->importNodes($nodeList);
|
||||
}
|
||||
|
||||
#[ReturnTypeWillChange]
|
||||
abstract public function current();
|
||||
|
||||
public function next(): void {
|
||||
$this->position++;
|
||||
}
|
||||
|
||||
public function key(): int {
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function valid(): bool {
|
||||
return $this->position < count($this->nodes);
|
||||
}
|
||||
|
||||
public function rewind(): void {
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
protected function getCurrentElement(): DOMElement {
|
||||
return $this->nodes[$this->position];
|
||||
}
|
||||
|
||||
private function importNodes(DOMNodeList $nodeList): void {
|
||||
foreach ($nodeList as $node) {
|
||||
if (!$node instanceof DOMElement) {
|
||||
throw new ElementCollectionException(
|
||||
sprintf('\DOMElement expected, got \%s', get_class($node))
|
||||
);
|
||||
}
|
||||
|
||||
$this->nodes[] = $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
vendor/phar-io/manifest/src/xml/ExtElement.php
vendored
Normal file
17
vendor/phar-io/manifest/src/xml/ExtElement.php
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class ExtElement extends ManifestElement {
|
||||
public function getName(): string {
|
||||
return $this->getAttributeValue('name');
|
||||
}
|
||||
}
|
||||
19
vendor/phar-io/manifest/src/xml/ExtElementCollection.php
vendored
Normal file
19
vendor/phar-io/manifest/src/xml/ExtElementCollection.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class ExtElementCollection extends ElementCollection {
|
||||
public function current(): ExtElement {
|
||||
return new ExtElement(
|
||||
$this->getCurrentElement()
|
||||
);
|
||||
}
|
||||
}
|
||||
21
vendor/phar-io/manifest/src/xml/ExtensionElement.php
vendored
Normal file
21
vendor/phar-io/manifest/src/xml/ExtensionElement.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class ExtensionElement extends ManifestElement {
|
||||
public function getFor(): string {
|
||||
return $this->getAttributeValue('for');
|
||||
}
|
||||
|
||||
public function getCompatible(): string {
|
||||
return $this->getAttributeValue('compatible');
|
||||
}
|
||||
}
|
||||
21
vendor/phar-io/manifest/src/xml/LicenseElement.php
vendored
Normal file
21
vendor/phar-io/manifest/src/xml/LicenseElement.php
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class LicenseElement extends ManifestElement {
|
||||
public function getType(): string {
|
||||
return $this->getAttributeValue('type');
|
||||
}
|
||||
|
||||
public function getUrl(): string {
|
||||
return $this->getAttributeValue('url');
|
||||
}
|
||||
}
|
||||
115
vendor/phar-io/manifest/src/xml/ManifestDocument.php
vendored
Normal file
115
vendor/phar-io/manifest/src/xml/ManifestDocument.php
vendored
Normal file
@ -0,0 +1,115 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use Throwable;
|
||||
use function count;
|
||||
use function file_get_contents;
|
||||
use function is_file;
|
||||
use function libxml_clear_errors;
|
||||
use function libxml_get_errors;
|
||||
use function libxml_use_internal_errors;
|
||||
use function sprintf;
|
||||
|
||||
class ManifestDocument {
|
||||
public const XMLNS = 'https://phar.io/xml/manifest/1.0';
|
||||
|
||||
/** @var DOMDocument */
|
||||
private $dom;
|
||||
|
||||
public static function fromFile(string $filename): ManifestDocument {
|
||||
if (!is_file($filename)) {
|
||||
throw new ManifestDocumentException(
|
||||
sprintf('File "%s" not found', $filename)
|
||||
);
|
||||
}
|
||||
|
||||
return self::fromString(
|
||||
file_get_contents($filename)
|
||||
);
|
||||
}
|
||||
|
||||
public static function fromString(string $xmlString): ManifestDocument {
|
||||
$prev = libxml_use_internal_errors(true);
|
||||
libxml_clear_errors();
|
||||
|
||||
try {
|
||||
$dom = new DOMDocument();
|
||||
$dom->loadXML($xmlString);
|
||||
$errors = libxml_get_errors();
|
||||
libxml_use_internal_errors($prev);
|
||||
} catch (Throwable $t) {
|
||||
throw new ManifestDocumentException($t->getMessage(), 0, $t);
|
||||
}
|
||||
|
||||
if (count($errors) !== 0) {
|
||||
throw new ManifestDocumentLoadingException($errors);
|
||||
}
|
||||
|
||||
return new self($dom);
|
||||
}
|
||||
|
||||
private function __construct(DOMDocument $dom) {
|
||||
$this->ensureCorrectDocumentType($dom);
|
||||
|
||||
$this->dom = $dom;
|
||||
}
|
||||
|
||||
public function getContainsElement(): ContainsElement {
|
||||
return new ContainsElement(
|
||||
$this->fetchElementByName('contains')
|
||||
);
|
||||
}
|
||||
|
||||
public function getCopyrightElement(): CopyrightElement {
|
||||
return new CopyrightElement(
|
||||
$this->fetchElementByName('copyright')
|
||||
);
|
||||
}
|
||||
|
||||
public function getRequiresElement(): RequiresElement {
|
||||
return new RequiresElement(
|
||||
$this->fetchElementByName('requires')
|
||||
);
|
||||
}
|
||||
|
||||
public function hasBundlesElement(): bool {
|
||||
return $this->dom->getElementsByTagNameNS(self::XMLNS, 'bundles')->length === 1;
|
||||
}
|
||||
|
||||
public function getBundlesElement(): BundlesElement {
|
||||
return new BundlesElement(
|
||||
$this->fetchElementByName('bundles')
|
||||
);
|
||||
}
|
||||
|
||||
private function ensureCorrectDocumentType(DOMDocument $dom): void {
|
||||
$root = $dom->documentElement;
|
||||
|
||||
if ($root->localName !== 'phar' || $root->namespaceURI !== self::XMLNS) {
|
||||
throw new ManifestDocumentException('Not a phar.io manifest document');
|
||||
}
|
||||
}
|
||||
|
||||
private function fetchElementByName(string $elementName): DOMElement {
|
||||
$element = $this->dom->getElementsByTagNameNS(self::XMLNS, $elementName)->item(0);
|
||||
|
||||
if (!$element instanceof DOMElement) {
|
||||
throw new ManifestDocumentException(
|
||||
sprintf('Element %s missing', $elementName)
|
||||
);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
72
vendor/phar-io/manifest/src/xml/ManifestElement.php
vendored
Normal file
72
vendor/phar-io/manifest/src/xml/ManifestElement.php
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* 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;
|
||||
use function sprintf;
|
||||
|
||||
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 hasAttribute(string $name): bool {
|
||||
return $this->element->hasAttribute($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;
|
||||
}
|
||||
}
|
||||
27
vendor/phar-io/manifest/src/xml/PhpElement.php
vendored
Normal file
27
vendor/phar-io/manifest/src/xml/PhpElement.php
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class PhpElement extends ManifestElement {
|
||||
public function getVersion(): string {
|
||||
return $this->getAttributeValue('version');
|
||||
}
|
||||
|
||||
public function hasExtElements(): bool {
|
||||
return $this->hasChild('ext');
|
||||
}
|
||||
|
||||
public function getExtElements(): ExtElementCollection {
|
||||
return new ExtElementCollection(
|
||||
$this->getChildrenByName('ext')
|
||||
);
|
||||
}
|
||||
}
|
||||
19
vendor/phar-io/manifest/src/xml/RequiresElement.php
vendored
Normal file
19
vendor/phar-io/manifest/src/xml/RequiresElement.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types = 1);
|
||||
/*
|
||||
* This file is part of PharIo\Manifest.
|
||||
*
|
||||
* Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
namespace PharIo\Manifest;
|
||||
|
||||
class RequiresElement extends ManifestElement {
|
||||
public function getPHPElement(): PhpElement {
|
||||
return new PhpElement(
|
||||
$this->getChildByName('php')
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user