first commit

This commit is contained in:
Sampanna Rimal
2024-08-27 17:48:06 +05:45
commit 53c0140f58
10839 changed files with 1125847 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
<?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 PharIo\Version\Exception as VersionException;
use PharIo\Version\Version;
use PharIo\Version\VersionConstraintParser;
use Throwable;
use function sprintf;
class ManifestDocumentMapper {
public function map(ManifestDocument $document): Manifest {
try {
$contains = $document->getContainsElement();
$type = $this->mapType($contains);
$copyright = $this->mapCopyright($document->getCopyrightElement());
$requirements = $this->mapRequirements($document->getRequiresElement());
$bundledComponents = $this->mapBundledComponents($document);
return new Manifest(
new ApplicationName($contains->getName()),
new Version($contains->getVersion()),
$type,
$copyright,
$requirements,
$bundledComponents
);
} catch (Throwable $e) {
throw new ManifestDocumentMapperException($e->getMessage(), (int)$e->getCode(), $e);
}
}
private function mapType(ContainsElement $contains): Type {
switch ($contains->getType()) {
case 'application':
return Type::application();
case 'library':
return Type::library();
case 'extension':
return $this->mapExtension($contains->getExtensionElement());
}
throw new ManifestDocumentMapperException(
sprintf('Unsupported type %s', $contains->getType())
);
}
private function mapCopyright(CopyrightElement $copyright): CopyrightInformation {
$authors = new AuthorCollection();
foreach ($copyright->getAuthorElements() as $authorElement) {
$authors->add(
new Author(
$authorElement->getName(),
$authorElement->hasEMail() ? new Email($authorElement->getEmail()) : null
)
);
}
$licenseElement = $copyright->getLicenseElement();
$license = new License(
$licenseElement->getType(),
new Url($licenseElement->getUrl())
);
return new CopyrightInformation(
$authors,
$license
);
}
private function mapRequirements(RequiresElement $requires): RequirementCollection {
$collection = new RequirementCollection();
$phpElement = $requires->getPHPElement();
$parser = new VersionConstraintParser;
try {
$versionConstraint = $parser->parse($phpElement->getVersion());
} catch (VersionException $e) {
throw new ManifestDocumentMapperException(
sprintf('Unsupported version constraint - %s', $e->getMessage()),
(int)$e->getCode(),
$e
);
}
$collection->add(
new PhpVersionRequirement(
$versionConstraint
)
);
if (!$phpElement->hasExtElements()) {
return $collection;
}
foreach ($phpElement->getExtElements() as $extElement) {
$collection->add(
new PhpExtensionRequirement($extElement->getName())
);
}
return $collection;
}
private function mapBundledComponents(ManifestDocument $document): BundledComponentCollection {
$collection = new BundledComponentCollection();
if (!$document->hasBundlesElement()) {
return $collection;
}
foreach ($document->getBundlesElement()->getComponentElements() as $componentElement) {
$collection->add(
new BundledComponent(
$componentElement->getName(),
new Version(
$componentElement->getVersion()
)
)
);
}
return $collection;
}
private function mapExtension(ExtensionElement $extension): Extension {
try {
$versionConstraint = (new VersionConstraintParser)->parse($extension->getCompatible());
return Type::extension(
new ApplicationName($extension->getFor()),
$versionConstraint
);
} catch (VersionException $e) {
throw new ManifestDocumentMapperException(
sprintf('Unsupported version constraint - %s', $e->getMessage()),
(int)$e->getCode(),
$e
);
}
}
}

View File

@@ -0,0 +1,47 @@
<?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 function sprintf;
class ManifestLoader {
public static function fromFile(string $filename): Manifest {
try {
return (new ManifestDocumentMapper())->map(
ManifestDocument::fromFile($filename)
);
} catch (Exception $e) {
throw new ManifestLoaderException(
sprintf('Loading %s failed.', $filename),
(int)$e->getCode(),
$e
);
}
}
public static function fromPhar(string $filename): Manifest {
return self::fromFile('phar://' . $filename . '/manifest.xml');
}
public static function fromString(string $manifest): Manifest {
try {
return (new ManifestDocumentMapper())->map(
ManifestDocument::fromString($manifest)
);
} catch (Exception $e) {
throw new ManifestLoaderException(
'Processing string failed',
(int)$e->getCode(),
$e
);
}
}
}

View File

@@ -0,0 +1,172 @@
<?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 PharIo\Version\AnyVersionConstraint;
use PharIo\Version\Version;
use PharIo\Version\VersionConstraint;
use XMLWriter;
use function count;
use function file_put_contents;
use function str_repeat;
/** @psalm-suppress MissingConstructor */
class ManifestSerializer {
/** @var XMLWriter */
private $xmlWriter;
public function serializeToFile(Manifest $manifest, string $filename): void {
file_put_contents(
$filename,
$this->serializeToString($manifest)
);
}
public function serializeToString(Manifest $manifest): string {
$this->startDocument();
$this->addContains($manifest->getName(), $manifest->getVersion(), $manifest->getType());
$this->addCopyright($manifest->getCopyrightInformation());
$this->addRequirements($manifest->getRequirements());
$this->addBundles($manifest->getBundledComponents());
return $this->finishDocument();
}
private function startDocument(): void {
$xmlWriter = new XMLWriter();
$xmlWriter->openMemory();
$xmlWriter->setIndent(true);
$xmlWriter->setIndentString(str_repeat(' ', 4));
$xmlWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startElement('phar');
$xmlWriter->writeAttribute('xmlns', 'https://phar.io/xml/manifest/1.0');
$this->xmlWriter = $xmlWriter;
}
private function finishDocument(): string {
$this->xmlWriter->endElement();
$this->xmlWriter->endDocument();
return $this->xmlWriter->outputMemory();
}
private function addContains(ApplicationName $name, Version $version, Type $type): void {
$this->xmlWriter->startElement('contains');
$this->xmlWriter->writeAttribute('name', $name->asString());
$this->xmlWriter->writeAttribute('version', $version->getVersionString());
switch (true) {
case $type->isApplication(): {
$this->xmlWriter->writeAttribute('type', 'application');
break;
}
case $type->isLibrary(): {
$this->xmlWriter->writeAttribute('type', 'library');
break;
}
case $type->isExtension(): {
$this->xmlWriter->writeAttribute('type', 'extension');
/* @var $type Extension */
$this->addExtension(
$type->getApplicationName(),
$type->getVersionConstraint()
);
break;
}
default: {
$this->xmlWriter->writeAttribute('type', 'custom');
}
}
$this->xmlWriter->endElement();
}
private function addCopyright(CopyrightInformation $copyrightInformation): void {
$this->xmlWriter->startElement('copyright');
foreach ($copyrightInformation->getAuthors() as $author) {
$this->xmlWriter->startElement('author');
$this->xmlWriter->writeAttribute('name', $author->getName());
$this->xmlWriter->writeAttribute('email', $author->getEmail()->asString());
$this->xmlWriter->endElement();
}
$license = $copyrightInformation->getLicense();
$this->xmlWriter->startElement('license');
$this->xmlWriter->writeAttribute('type', $license->getName());
$this->xmlWriter->writeAttribute('url', $license->getUrl()->asString());
$this->xmlWriter->endElement();
$this->xmlWriter->endElement();
}
private function addRequirements(RequirementCollection $requirementCollection): void {
$phpRequirement = new AnyVersionConstraint();
$extensions = [];
foreach ($requirementCollection as $requirement) {
if ($requirement instanceof PhpVersionRequirement) {
$phpRequirement = $requirement->getVersionConstraint();
continue;
}
if ($requirement instanceof PhpExtensionRequirement) {
$extensions[] = $requirement->asString();
}
}
$this->xmlWriter->startElement('requires');
$this->xmlWriter->startElement('php');
$this->xmlWriter->writeAttribute('version', $phpRequirement->asString());
foreach ($extensions as $extension) {
$this->xmlWriter->startElement('ext');
$this->xmlWriter->writeAttribute('name', $extension);
$this->xmlWriter->endElement();
}
$this->xmlWriter->endElement();
$this->xmlWriter->endElement();
}
private function addBundles(BundledComponentCollection $bundledComponentCollection): void {
if (count($bundledComponentCollection) === 0) {
return;
}
$this->xmlWriter->startElement('bundles');
foreach ($bundledComponentCollection as $bundledComponent) {
$this->xmlWriter->startElement('component');
$this->xmlWriter->writeAttribute('name', $bundledComponent->getName());
$this->xmlWriter->writeAttribute('version', $bundledComponent->getVersion()->getVersionString());
$this->xmlWriter->endElement();
}
$this->xmlWriter->endElement();
}
private function addExtension(ApplicationName $applicationName, VersionConstraint $versionConstraint): void {
$this->xmlWriter->startElement('extension');
$this->xmlWriter->writeAttribute('for', $applicationName->asString());
$this->xmlWriter->writeAttribute('compatible', $versionConstraint->asString());
$this->xmlWriter->endElement();
}
}

View File

@@ -0,0 +1,16 @@
<?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 InvalidArgumentException;
class ElementCollectionException extends InvalidArgumentException implements Exception {
}

View File

@@ -0,0 +1,16 @@
<?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 Throwable;
interface Exception extends Throwable {
}

View 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;
use InvalidArgumentException;
class InvalidApplicationNameException extends InvalidArgumentException implements Exception {
public const InvalidFormat = 2;
}

View File

@@ -0,0 +1,16 @@
<?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 InvalidArgumentException;
class InvalidEmailException extends InvalidArgumentException implements Exception {
}

View File

@@ -0,0 +1,16 @@
<?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 InvalidArgumentException;
class InvalidUrlException extends InvalidArgumentException implements Exception {
}

View File

@@ -0,0 +1,16 @@
<?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 RuntimeException;
class ManifestDocumentException extends RuntimeException implements Exception {
}

View File

@@ -0,0 +1,47 @@
<?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 LibXMLError;
use function sprintf;
class ManifestDocumentLoadingException extends \Exception implements Exception {
/** @var LibXMLError[] */
private $libxmlErrors;
/**
* ManifestDocumentLoadingException constructor.
*
* @param LibXMLError[] $libxmlErrors
*/
public function __construct(array $libxmlErrors) {
$this->libxmlErrors = $libxmlErrors;
$first = $this->libxmlErrors[0];
parent::__construct(
sprintf(
'%s (Line: %d / Column: %d / File: %s)',
$first->message,
$first->line,
$first->column,
$first->file
),
$first->code
);
}
/**
* @return LibXMLError[]
*/
public function getLibxmlErrors(): array {
return $this->libxmlErrors;
}
}

View File

@@ -0,0 +1,16 @@
<?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 RuntimeException;
class ManifestDocumentMapperException extends RuntimeException implements Exception {
}

View File

@@ -0,0 +1,16 @@
<?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 RuntimeException;
class ManifestElementException extends RuntimeException implements Exception {
}

View File

@@ -0,0 +1,14 @@
<?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 ManifestLoaderException extends \Exception implements Exception {
}

View File

@@ -0,0 +1,16 @@
<?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 InvalidArgumentException;
class NoEmailAddressException extends InvalidArgumentException implements Exception {
}

View 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 Application extends Type {
public function isApplication(): bool {
return true;
}
}

View File

@@ -0,0 +1,41 @@
<?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 function preg_match;
use function sprintf;
class ApplicationName {
/** @var string */
private $name;
public function __construct(string $name) {
$this->ensureValidFormat($name);
$this->name = $name;
}
public function asString(): string {
return $this->name;
}
public function isEqual(ApplicationName $name): bool {
return $this->name === $name->name;
}
private function ensureValidFormat(string $name): void {
if (!preg_match('#\w/\w#', $name)) {
throw new InvalidApplicationNameException(
sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
InvalidApplicationNameException::InvalidFormat
);
}
}
}

View File

@@ -0,0 +1,57 @@
<?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 function sprintf;
class Author {
/** @var string */
private $name;
/** @var null|Email */
private $email;
public function __construct(string $name, ?Email $email = null) {
$this->name = $name;
$this->email = $email;
}
public function asString(): string {
if (!$this->hasEmail()) {
return $this->name;
}
return sprintf(
'%s <%s>',
$this->name,
$this->email->asString()
);
}
public function getName(): string {
return $this->name;
}
/**
* @psalm-assert-if-true Email $this->email
*/
public function hasEmail(): bool {
return $this->email !== null;
}
public function getEmail(): Email {
if (!$this->hasEmail()) {
throw new NoEmailAddressException();
}
return $this->email;
}
}

View File

@@ -0,0 +1,40 @@
<?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 Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,Author> */
class AuthorCollection implements Countable, IteratorAggregate {
/** @var Author[] */
private $authors = [];
public function add(Author $author): void {
$this->authors[] = $author;
}
/**
* @return Author[]
*/
public function getAuthors(): array {
return $this->authors;
}
public function count(): int {
return count($this->authors);
}
public function getIterator(): AuthorCollectionIterator {
return new AuthorCollectionIterator($this);
}
}

View File

@@ -0,0 +1,47 @@
<?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 Iterator;
use function count;
/** @template-implements Iterator<int,Author> */
class AuthorCollectionIterator implements Iterator {
/** @var Author[] */
private $authors;
/** @var int */
private $position = 0;
public function __construct(AuthorCollection $authors) {
$this->authors = $authors->getAuthors();
}
public function rewind(): void {
$this->position = 0;
}
public function valid(): bool {
return $this->position < count($this->authors);
}
public function key(): int {
return $this->position;
}
public function current(): Author {
return $this->authors[$this->position];
}
public function next(): void {
$this->position++;
}
}

View File

@@ -0,0 +1,34 @@
<?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 PharIo\Version\Version;
class BundledComponent {
/** @var string */
private $name;
/** @var Version */
private $version;
public function __construct(string $name, Version $version) {
$this->name = $name;
$this->version = $version;
}
public function getName(): string {
return $this->name;
}
public function getVersion(): Version {
return $this->version;
}
}

View File

@@ -0,0 +1,40 @@
<?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 Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,BundledComponent> */
class BundledComponentCollection implements Countable, IteratorAggregate {
/** @var BundledComponent[] */
private $bundledComponents = [];
public function add(BundledComponent $bundledComponent): void {
$this->bundledComponents[] = $bundledComponent;
}
/**
* @return BundledComponent[]
*/
public function getBundledComponents(): array {
return $this->bundledComponents;
}
public function count(): int {
return count($this->bundledComponents);
}
public function getIterator(): BundledComponentCollectionIterator {
return new BundledComponentCollectionIterator($this);
}
}

View File

@@ -0,0 +1,47 @@
<?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 Iterator;
use function count;
/** @template-implements Iterator<int,BundledComponent> */
class BundledComponentCollectionIterator implements Iterator {
/** @var BundledComponent[] */
private $bundledComponents;
/** @var int */
private $position = 0;
public function __construct(BundledComponentCollection $bundledComponents) {
$this->bundledComponents = $bundledComponents->getBundledComponents();
}
public function rewind(): void {
$this->position = 0;
}
public function valid(): bool {
return $this->position < count($this->bundledComponents);
}
public function key(): int {
return $this->position;
}
public function current(): BundledComponent {
return $this->bundledComponents[$this->position];
}
public function next(): void {
$this->position++;
}
}

View File

@@ -0,0 +1,32 @@
<?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 CopyrightInformation {
/** @var AuthorCollection */
private $authors;
/** @var License */
private $license;
public function __construct(AuthorCollection $authors, License $license) {
$this->authors = $authors;
$this->license = $license;
}
public function getAuthors(): AuthorCollection {
return $this->authors;
}
public function getLicense(): License {
return $this->license;
}
}

View File

@@ -0,0 +1,35 @@
<?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 const FILTER_VALIDATE_EMAIL;
use function filter_var;
class Email {
/** @var string */
private $email;
public function __construct(string $email) {
$this->ensureEmailIsValid($email);
$this->email = $email;
}
public function asString(): string {
return $this->email;
}
private function ensureEmailIsValid(string $url): void {
if (filter_var($url, FILTER_VALIDATE_EMAIL) === false) {
throw new InvalidEmailException;
}
}
}

View File

@@ -0,0 +1,47 @@
<?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 PharIo\Version\Version;
use PharIo\Version\VersionConstraint;
class Extension extends Type {
/** @var ApplicationName */
private $application;
/** @var VersionConstraint */
private $versionConstraint;
public function __construct(ApplicationName $application, VersionConstraint $versionConstraint) {
$this->application = $application;
$this->versionConstraint = $versionConstraint;
}
public function getApplicationName(): ApplicationName {
return $this->application;
}
public function getVersionConstraint(): VersionConstraint {
return $this->versionConstraint;
}
public function isExtension(): bool {
return true;
}
public function isExtensionFor(ApplicationName $name): bool {
return $this->application->isEqual($name);
}
public function isCompatibleWith(ApplicationName $name, Version $version): bool {
return $this->isExtensionFor($name) && $this->versionConstraint->complies($version);
}
}

View 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 Library extends Type {
public function isLibrary(): bool {
return true;
}
}

View File

@@ -0,0 +1,32 @@
<?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 License {
/** @var string */
private $name;
/** @var Url */
private $url;
public function __construct(string $name, Url $url) {
$this->name = $name;
$this->url = $url;
}
public function getName(): string {
return $this->name;
}
public function getUrl(): Url {
return $this->url;
}
}

View File

@@ -0,0 +1,93 @@
<?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 PharIo\Version\Version;
class Manifest {
/** @var ApplicationName */
private $name;
/** @var Version */
private $version;
/** @var Type */
private $type;
/** @var CopyrightInformation */
private $copyrightInformation;
/** @var RequirementCollection */
private $requirements;
/** @var BundledComponentCollection */
private $bundledComponents;
public function __construct(ApplicationName $name, Version $version, Type $type, CopyrightInformation $copyrightInformation, RequirementCollection $requirements, BundledComponentCollection $bundledComponents) {
$this->name = $name;
$this->version = $version;
$this->type = $type;
$this->copyrightInformation = $copyrightInformation;
$this->requirements = $requirements;
$this->bundledComponents = $bundledComponents;
}
public function getName(): ApplicationName {
return $this->name;
}
public function getVersion(): Version {
return $this->version;
}
public function getType(): Type {
return $this->type;
}
public function getCopyrightInformation(): CopyrightInformation {
return $this->copyrightInformation;
}
public function getRequirements(): RequirementCollection {
return $this->requirements;
}
public function getBundledComponents(): BundledComponentCollection {
return $this->bundledComponents;
}
public function isApplication(): bool {
return $this->type->isApplication();
}
public function isLibrary(): bool {
return $this->type->isLibrary();
}
public function isExtension(): bool {
return $this->type->isExtension();
}
public function isExtensionFor(ApplicationName $application, ?Version $version = null): bool {
if (!$this->isExtension()) {
return false;
}
/** @var Extension $type */
$type = $this->type;
if ($version !== null) {
return $type->isCompatibleWith($application, $version);
}
return $type->isExtensionFor($application);
}
}

View File

@@ -0,0 +1,24 @@
<?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 PhpExtensionRequirement implements Requirement {
/** @var string */
private $extension;
public function __construct(string $extension) {
$this->extension = $extension;
}
public function asString(): string {
return $this->extension;
}
}

View File

@@ -0,0 +1,26 @@
<?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 PharIo\Version\VersionConstraint;
class PhpVersionRequirement implements Requirement {
/** @var VersionConstraint */
private $versionConstraint;
public function __construct(VersionConstraint $versionConstraint) {
$this->versionConstraint = $versionConstraint;
}
public function getVersionConstraint(): VersionConstraint {
return $this->versionConstraint;
}
}

View File

@@ -0,0 +1,14 @@
<?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;
interface Requirement {
}

View File

@@ -0,0 +1,40 @@
<?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 Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,Requirement> */
class RequirementCollection implements Countable, IteratorAggregate {
/** @var Requirement[] */
private $requirements = [];
public function add(Requirement $requirement): void {
$this->requirements[] = $requirement;
}
/**
* @return Requirement[]
*/
public function getRequirements(): array {
return $this->requirements;
}
public function count(): int {
return count($this->requirements);
}
public function getIterator(): RequirementCollectionIterator {
return new RequirementCollectionIterator($this);
}
}

View File

@@ -0,0 +1,47 @@
<?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 Iterator;
use function count;
/** @template-implements Iterator<int,Requirement> */
class RequirementCollectionIterator implements Iterator {
/** @var Requirement[] */
private $requirements;
/** @var int */
private $position = 0;
public function __construct(RequirementCollection $requirements) {
$this->requirements = $requirements->getRequirements();
}
public function rewind(): void {
$this->position = 0;
}
public function valid(): bool {
return $this->position < count($this->requirements);
}
public function key(): int {
return $this->position;
}
public function current(): Requirement {
return $this->requirements[$this->position];
}
public function next(): void {
$this->position++;
}
}

View File

@@ -0,0 +1,42 @@
<?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 PharIo\Version\VersionConstraint;
abstract class Type {
public static function application(): Application {
return new Application;
}
public static function library(): Library {
return new Library;
}
public static function extension(ApplicationName $application, VersionConstraint $versionConstraint): Extension {
return new Extension($application, $versionConstraint);
}
/** @psalm-assert-if-true Application $this */
public function isApplication(): bool {
return false;
}
/** @psalm-assert-if-true Library $this */
public function isLibrary(): bool {
return false;
}
/** @psalm-assert-if-true Extension $this */
public function isExtension(): bool {
return false;
}
}

View File

@@ -0,0 +1,38 @@
<?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 const FILTER_VALIDATE_URL;
use function filter_var;
class Url {
/** @var string */
private $url;
public function __construct(string $url) {
$this->ensureUrlIsValid($url);
$this->url = $url;
}
public function asString(): string {
return $this->url;
}
/**
* @throws InvalidUrlException
*/
private function ensureUrlIsValid(string $url): void {
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new InvalidUrlException;
}
}
}

View 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');
}
}

View 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()
);
}
}

View 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')
);
}
}

View 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');
}
}

View 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()
);
}
}

View 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')
);
}
}

View 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')
);
}
}

View 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;
}
}
}

View 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');
}
}

View 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()
);
}
}

View 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');
}
}

View 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');
}
}

View 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;
}
}

View 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;
}
}

View 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')
);
}
}

View 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')
);
}
}