Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -2,6 +2,14 @@
All notable changes to phar-io/manifest are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [2.0.4] - 03-03-2024
### Changed
- Make `EMail` an optional attribute for author
- Stick with PHP 7.2 compatibilty
- Do not use implict nullable type (thanks @sebastianbergmann), this should make things work on PHP 8.4
## [2.0.3] - 20.07.2021
- Fixed PHP 7.2 / PHP 7.3 incompatibility introduced in previous release
@@ -26,7 +34,8 @@ This release now requires PHP 7.2+
### Unreleased
[Unreleased]: https://github.com/phar-io/manifest/compare/2.0.3...HEAD
[Unreleased]: https://github.com/phar-io/manifest/compare/2.1.0...HEAD
[2.1.0]: https://github.com/phar-io/manifest/compare/2.0.3...2.1.0
[2.0.3]: https://github.com/phar-io/manifest/compare/2.0.2...2.0.3
[2.0.2]: https://github.com/phar-io/manifest/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/phar-io/manifest/compare/2.0.0...2.0.1

View File

@@ -2,10 +2,6 @@
Component for reading [phar.io](https://phar.io/) manifest information from a [PHP Archive (PHAR)](http://php.net/phar).
[![Build Status](https://travis-ci.org/phar-io/manifest.svg?branch=master)](https://travis-ci.org/phar-io/manifest)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phar-io/manifest/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phar-io/manifest/?branch=master)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d8cc6035-69ad-477d-bd1a-ccc605480fd7/mini.png)](https://insight.sensiolabs.com/projects/d8cc6035-69ad-477d-bd1a-ccc605480fd7)
## Installation
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
@@ -16,8 +12,9 @@ If you only need this library during development, for instance to run your proje
composer require --dev phar-io/manifest
## Usage
## Usage Examples
### Read from `manifest.xml`
```php
use PharIo\Manifest\ManifestLoader;
use PharIo\Manifest\ManifestSerializer;
@@ -28,3 +25,154 @@ var_dump($manifest);
echo (new ManifestSerializer)->serializeToString($manifest);
```
<details>
<summary>Output</summary>
```shell
object(PharIo\Manifest\Manifest)#14 (6) {
["name":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\ApplicationName)#10 (1) {
["name":"PharIo\Manifest\ApplicationName":private]=>
string(12) "some/library"
}
["version":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Version\Version)#12 (5) {
["originalVersionString":"PharIo\Version\Version":private]=>
string(5) "1.0.0"
["major":"PharIo\Version\Version":private]=>
object(PharIo\Version\VersionNumber)#13 (1) {
["value":"PharIo\Version\VersionNumber":private]=>
int(1)
}
["minor":"PharIo\Version\Version":private]=>
object(PharIo\Version\VersionNumber)#23 (1) {
["value":"PharIo\Version\VersionNumber":private]=>
int(0)
}
["patch":"PharIo\Version\Version":private]=>
object(PharIo\Version\VersionNumber)#22 (1) {
["value":"PharIo\Version\VersionNumber":private]=>
int(0)
}
["preReleaseSuffix":"PharIo\Version\Version":private]=>
NULL
}
["type":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\Library)#6 (0) {
}
["copyrightInformation":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\CopyrightInformation)#19 (2) {
["authors":"PharIo\Manifest\CopyrightInformation":private]=>
object(PharIo\Manifest\AuthorCollection)#9 (1) {
["authors":"PharIo\Manifest\AuthorCollection":private]=>
array(1) {
[0]=>
object(PharIo\Manifest\Author)#15 (2) {
["name":"PharIo\Manifest\Author":private]=>
string(13) "Reiner Zufall"
["email":"PharIo\Manifest\Author":private]=>
object(PharIo\Manifest\Email)#16 (1) {
["email":"PharIo\Manifest\Email":private]=>
string(16) "reiner@zufall.de"
}
}
}
}
["license":"PharIo\Manifest\CopyrightInformation":private]=>
object(PharIo\Manifest\License)#11 (2) {
["name":"PharIo\Manifest\License":private]=>
string(12) "BSD-3-Clause"
["url":"PharIo\Manifest\License":private]=>
object(PharIo\Manifest\Url)#18 (1) {
["url":"PharIo\Manifest\Url":private]=>
string(26) "https://domain.tld/LICENSE"
}
}
}
["requirements":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\RequirementCollection)#17 (1) {
["requirements":"PharIo\Manifest\RequirementCollection":private]=>
array(1) {
[0]=>
object(PharIo\Manifest\PhpVersionRequirement)#20 (1) {
["versionConstraint":"PharIo\Manifest\PhpVersionRequirement":private]=>
object(PharIo\Version\SpecificMajorAndMinorVersionConstraint)#24 (3) {
["originalValue":"PharIo\Version\AbstractVersionConstraint":private]=>
string(3) "7.0"
["major":"PharIo\Version\SpecificMajorAndMinorVersionConstraint":private]=>
int(7)
["minor":"PharIo\Version\SpecificMajorAndMinorVersionConstraint":private]=>
int(0)
}
}
}
}
["bundledComponents":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\BundledComponentCollection)#8 (1) {
["bundledComponents":"PharIo\Manifest\BundledComponentCollection":private]=>
array(0) {
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="some/library" version="1.0.0" type="library"/>
<copyright>
<author name="Reiner Zufall" email="reiner@zufall.de"/>
<license type="BSD-3-Clause" url="https://domain.tld/LICENSE"/>
</copyright>
<requires>
<php version="7.0"/>
</requires>
</phar>
```
</details>
### Create via API
```php
$bundled = new \PharIo\Manifest\BundledComponentCollection();
$bundled->add(
new \PharIo\Manifest\BundledComponent('vendor/packageA', new \PharIo\Version\Version('1.2.3-dev')
)
);
$manifest = new PharIo\Manifest\Manifest(
new \PharIo\Manifest\ApplicationName('vendor/package'),
new \PharIo\Version\Version('1.0.0'),
new \PharIo\Manifest\Library(),
new \PharIo\Manifest\CopyrightInformation(
new \PharIo\Manifest\AuthorCollection(),
new \PharIo\Manifest\License(
'BSD-3-Clause',
new \PharIo\Manifest\Url('https://spdx.org/licenses/BSD-3-Clause.html')
)
),
new \PharIo\Manifest\RequirementCollection(),
$bundled
);
echo (new ManifestSerializer)->serializeToString($manifest);
```
<details>
<summary>Output</summary>
```xml
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="vendor/package" version="1.0.0" type="library"/>
<copyright>
<license type="BSD-3-Clause" url="https://spdx.org/licenses/BSD-3-Clause.html"/>
</copyright>
<requires>
<php version="*"/>
</requires>
<bundles>
<component name="vendor/packageA" version="1.2.3-dev"/>
</bundles>
</phar>
```
</details>

View File

@@ -26,6 +26,7 @@
"php": "^7.2 || ^8.0",
"ext-dom": "*",
"ext-phar": "*",
"ext-libxml": "*",
"ext-xmlwriter": "*",
"phar-io/version": "^3.0.1"
},

View File

@@ -4,24 +4,24 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f2ac4614ce4f7273fd54a64b65fd047a",
"content-hash": "279b3c4fe44357abd924fdcc0cfa5664",
"packages": [
{
"name": "phar-io/version",
"version": "3.0.1",
"version": "3.2.1",
"source": {
"type": "git",
"url": "https://github.com/phar-io/version.git",
"reference": "d06a5000ac1a258a7d035295f0bd4ae7c859bc4f"
"reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phar-io/version/zipball/d06a5000ac1a258a7d035295f0bd4ae7c859bc4f",
"reference": "d06a5000ac1a258a7d035295f0bd4ae7c859bc4f",
"url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74",
"reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74",
"shasum": ""
},
"require": {
"php": "^7.2"
"php": "^7.2 || ^8.0"
},
"type": "library",
"autoload": {
@@ -51,7 +51,11 @@
}
],
"description": "Library for handling version information and constraints",
"time": "2020-05-09T21:27:55+00:00"
"support": {
"issues": "https://github.com/phar-io/version/issues",
"source": "https://github.com/phar-io/version/tree/3.2.1"
},
"time": "2022-02-21T01:04:05+00:00"
}
],
"packages-dev": [],
@@ -61,10 +65,12 @@
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"ext-dom": "*",
"ext-phar": "*",
"ext-libxml": "*",
"ext-xmlwriter": "*"
},
"platform-dev": []
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View File

@@ -2,16 +2,19 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 {
@@ -30,9 +33,7 @@ class ManifestDocumentMapper {
$requirements,
$bundledComponents
);
} catch (VersionException $e) {
throw new ManifestDocumentMapperException($e->getMessage(), (int)$e->getCode(), $e);
} catch (Exception $e) {
} catch (Throwable $e) {
throw new ManifestDocumentMapperException($e->getMessage(), (int)$e->getCode(), $e);
}
}
@@ -48,7 +49,7 @@ class ManifestDocumentMapper {
}
throw new ManifestDocumentMapperException(
\sprintf('Unsupported type %s', $contains->getType())
sprintf('Unsupported type %s', $contains->getType())
);
}
@@ -59,7 +60,7 @@ class ManifestDocumentMapper {
$authors->add(
new Author(
$authorElement->getName(),
new Email($authorElement->getEmail())
$authorElement->hasEMail() ? new Email($authorElement->getEmail()) : null
)
);
}
@@ -85,7 +86,7 @@ class ManifestDocumentMapper {
$versionConstraint = $parser->parse($phpElement->getVersion());
} catch (VersionException $e) {
throw new ManifestDocumentMapperException(
\sprintf('Unsupported version constraint - %s', $e->getMessage()),
sprintf('Unsupported version constraint - %s', $e->getMessage()),
(int)$e->getCode(),
$e
);
@@ -141,7 +142,7 @@ class ManifestDocumentMapper {
);
} catch (VersionException $e) {
throw new ManifestDocumentMapperException(
\sprintf('Unsupported version constraint - %s', $e->getMessage()),
sprintf('Unsupported version constraint - %s', $e->getMessage()),
(int)$e->getCode(),
$e
);

View File

@@ -2,13 +2,16 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 {
@@ -17,7 +20,7 @@ class ManifestLoader {
);
} catch (Exception $e) {
throw new ManifestLoaderException(
\sprintf('Loading %s failed.', $filename),
sprintf('Loading %s failed.', $filename),
(int)$e->getCode(),
$e
);

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;
@@ -13,6 +14,9 @@ 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 {
@@ -20,7 +24,7 @@ class ManifestSerializer {
private $xmlWriter;
public function serializeToFile(Manifest $manifest, string $filename): void {
\file_put_contents(
file_put_contents(
$filename,
$this->serializeToString($manifest)
);
@@ -41,7 +45,7 @@ class ManifestSerializer {
$xmlWriter = new XMLWriter();
$xmlWriter->openMemory();
$xmlWriter->setIndent(true);
$xmlWriter->setIndentString(\str_repeat(' ', 4));
$xmlWriter->setIndentString(str_repeat(' ', 4));
$xmlWriter->startDocument('1.0', 'UTF-8');
$xmlWriter->startElement('phar');
$xmlWriter->writeAttribute('xmlns', 'https://phar.io/xml/manifest/1.0');
@@ -144,7 +148,7 @@ class ManifestSerializer {
}
private function addBundles(BundledComponentCollection $bundledComponentCollection): void {
if (\count($bundledComponentCollection) === 0) {
if (count($bundledComponentCollection) === 0) {
return;
}
$this->xmlWriter->startElement('bundles');

View File

@@ -2,12 +2,15 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 ElementCollectionException extends \InvalidArgumentException implements Exception {
use InvalidArgumentException;
class ElementCollectionException extends InvalidArgumentException implements Exception {
}

View File

@@ -2,12 +2,15 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 Exception extends \Throwable {
use Throwable;
interface Exception extends Throwable {
}

View File

@@ -2,13 +2,16 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 InvalidApplicationNameException extends \InvalidArgumentException implements Exception {
use InvalidArgumentException;
class InvalidApplicationNameException extends InvalidArgumentException implements Exception {
public const InvalidFormat = 2;
}

View File

@@ -2,12 +2,15 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 InvalidEmailException extends \InvalidArgumentException implements Exception {
use InvalidArgumentException;
class InvalidEmailException extends InvalidArgumentException implements Exception {
}

View File

@@ -2,12 +2,15 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 InvalidUrlException extends \InvalidArgumentException implements Exception {
use InvalidArgumentException;
class InvalidUrlException extends InvalidArgumentException implements Exception {
}

View File

@@ -1,5 +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;
class ManifestDocumentException extends \RuntimeException implements Exception {
use RuntimeException;
class ManifestDocumentException extends RuntimeException implements Exception {
}

View File

@@ -2,14 +2,16 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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[] */
@@ -25,7 +27,7 @@ class ManifestDocumentLoadingException extends \Exception implements Exception {
$first = $this->libxmlErrors[0];
parent::__construct(
\sprintf(
sprintf(
'%s (Line: %d / Column: %d / File: %s)',
$first->message,
$first->line,

View File

@@ -1,5 +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;
class ManifestDocumentMapperException extends \RuntimeException implements Exception {
use RuntimeException;
class ManifestDocumentMapperException extends RuntimeException implements Exception {
}

View File

@@ -1,5 +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;
class ManifestElementException extends \RuntimeException implements Exception {
use RuntimeException;
class ManifestElementException extends RuntimeException implements Exception {
}

View File

@@ -1,4 +1,13 @@
<?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

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,13 +2,17 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;
@@ -27,9 +31,9 @@ class ApplicationName {
}
private function ensureValidFormat(string $name): void {
if (!\preg_match('#\w/\w#', $name)) {
if (!preg_match('#\w/\w#', $name)) {
throw new InvalidApplicationNameException(
\sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
InvalidApplicationNameException::InvalidFormat
);
}

View File

@@ -2,27 +2,34 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 Email */
/** @var null|Email */
private $email;
public function __construct(string $name, Email $email) {
public function __construct(string $name, ?Email $email = null) {
$this->name = $name;
$this->email = $email;
}
public function asString(): string {
return \sprintf(
if (!$this->hasEmail()) {
return $this->name;
}
return sprintf(
'%s <%s>',
$this->name,
$this->email->asString()
@@ -33,7 +40,18 @@ class Author {
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

@@ -2,14 +2,20 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 AuthorCollection implements \Countable, \IteratorAggregate {
use Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,Author> */
class AuthorCollection implements Countable, IteratorAggregate {
/** @var Author[] */
private $authors = [];
@@ -25,7 +31,7 @@ class AuthorCollection implements \Countable, \IteratorAggregate {
}
public function count(): int {
return \count($this->authors);
return count($this->authors);
}
public function getIterator(): AuthorCollectionIterator {

View File

@@ -2,14 +2,19 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 AuthorCollectionIterator implements \Iterator {
use Iterator;
use function count;
/** @template-implements Iterator<int,Author> */
class AuthorCollectionIterator implements Iterator {
/** @var Author[] */
private $authors;
@@ -25,7 +30,7 @@ class AuthorCollectionIterator implements \Iterator {
}
public function valid(): bool {
return $this->position < \count($this->authors);
return $this->position < count($this->authors);
}
public function key(): int {

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,14 +2,20 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 BundledComponentCollection implements \Countable, \IteratorAggregate {
use Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,BundledComponent> */
class BundledComponentCollection implements Countable, IteratorAggregate {
/** @var BundledComponent[] */
private $bundledComponents = [];
@@ -25,7 +31,7 @@ class BundledComponentCollection implements \Countable, \IteratorAggregate {
}
public function count(): int {
return \count($this->bundledComponents);
return count($this->bundledComponents);
}
public function getIterator(): BundledComponentCollectionIterator {

View File

@@ -2,14 +2,19 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 BundledComponentCollectionIterator implements \Iterator {
use Iterator;
use function count;
/** @template-implements Iterator<int,BundledComponent> */
class BundledComponentCollectionIterator implements Iterator {
/** @var BundledComponent[] */
private $bundledComponents;
@@ -25,7 +30,7 @@ class BundledComponentCollectionIterator implements \Iterator {
}
public function valid(): bool {
return $this->position < \count($this->bundledComponents);
return $this->position < count($this->bundledComponents);
}
public function key(): int {

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,13 +2,17 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;
@@ -24,7 +28,7 @@ class Email {
}
private function ensureEmailIsValid(string $url): void {
if (\filter_var($url, \FILTER_VALIDATE_EMAIL) === false) {
if (filter_var($url, FILTER_VALIDATE_EMAIL) === false) {
throw new InvalidEmailException;
}
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;
@@ -75,7 +76,7 @@ class Manifest {
return $this->type->isExtension();
}
public function isExtensionFor(ApplicationName $application, Version $version = null): bool {
public function isExtensionFor(ApplicationName $application, ?Version $version = null): bool {
if (!$this->isExtension()) {
return false;
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,14 +2,20 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 RequirementCollection implements \Countable, \IteratorAggregate {
use Countable;
use IteratorAggregate;
use function count;
/** @template-implements IteratorAggregate<int,Requirement> */
class RequirementCollection implements Countable, IteratorAggregate {
/** @var Requirement[] */
private $requirements = [];
@@ -25,7 +31,7 @@ class RequirementCollection implements \Countable, \IteratorAggregate {
}
public function count(): int {
return \count($this->requirements);
return count($this->requirements);
}
public function getIterator(): RequirementCollectionIterator {

View File

@@ -2,14 +2,19 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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 RequirementCollectionIterator implements \Iterator {
use Iterator;
use function count;
/** @template-implements Iterator<int,Requirement> */
class RequirementCollectionIterator implements Iterator {
/** @var Requirement[] */
private $requirements;
@@ -25,7 +30,7 @@ class RequirementCollectionIterator implements \Iterator {
}
public function valid(): bool {
return $this->position < \count($this->requirements);
return $this->position < count($this->requirements);
}
public function key(): int {

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,13 +2,17 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;
@@ -24,12 +28,10 @@ class Url {
}
/**
* @param string $url
*
* @throws InvalidUrlException
*/
private function ensureUrlIsValid($url): void {
if (\filter_var($url, \FILTER_VALIDATE_URL) === false) {
private function ensureUrlIsValid(string $url): void {
if (filter_var($url, FILTER_VALIDATE_URL) === false) {
throw new InvalidUrlException;
}
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;
@@ -17,4 +18,8 @@ class AuthorElement extends ManifestElement {
public function getEmail(): string {
return $this->getAttributeValue('email');
}
public function hasEMail(): bool {
return $this->hasAttribute('email');
}
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,17 +2,24 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;
abstract class ElementCollection implements \Iterator {
/** @template-implements Iterator<int,DOMElement> */
abstract class ElementCollection implements Iterator {
/** @var DOMElement[] */
private $nodes = [];
@@ -24,7 +31,7 @@ abstract class ElementCollection implements \Iterator {
$this->importNodes($nodeList);
}
#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
abstract public function current();
public function next(): void {
@@ -36,7 +43,7 @@ abstract class ElementCollection implements \Iterator {
}
public function valid(): bool {
return $this->position < \count($this->nodes);
return $this->position < count($this->nodes);
}
public function rewind(): void {
@@ -51,7 +58,7 @@ abstract class ElementCollection implements \Iterator {
foreach ($nodeList as $node) {
if (!$node instanceof DOMElement) {
throw new ElementCollectionException(
\sprintf('\DOMElement expected, got \%s', \get_class($node))
sprintf('\DOMElement expected, got \%s', get_class($node))
);
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,15 +2,24 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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';
@@ -19,28 +28,31 @@ class ManifestDocument {
private $dom;
public static function fromFile(string $filename): ManifestDocument {
if (!\file_exists($filename)) {
if (!is_file($filename)) {
throw new ManifestDocumentException(
\sprintf('File "%s" not found', $filename)
sprintf('File "%s" not found', $filename)
);
}
return self::fromString(
\file_get_contents($filename)
file_get_contents($filename)
);
}
public static function fromString(string $xmlString): ManifestDocument {
$prev = \libxml_use_internal_errors(true);
\libxml_clear_errors();
$prev = libxml_use_internal_errors(true);
libxml_clear_errors();
$dom = new DOMDocument();
$dom->loadXML($xmlString);
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);
}
$errors = \libxml_get_errors();
\libxml_use_internal_errors($prev);
if (\count($errors) !== 0) {
if (count($errors) !== 0) {
throw new ManifestDocumentLoadingException($errors);
}
@@ -94,7 +106,7 @@ class ManifestDocument {
if (!$element instanceof DOMElement) {
throw new ManifestDocumentException(
\sprintf('Element %s missing', $elementName)
sprintf('Element %s missing', $elementName)
);
}

View File

@@ -2,15 +2,17 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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';
@@ -25,7 +27,7 @@ class ManifestElement {
protected function getAttributeValue(string $name): string {
if (!$this->element->hasAttribute($name)) {
throw new ManifestElementException(
\sprintf(
sprintf(
'Attribute %s not set on element %s',
$name,
$this->element->localName
@@ -36,12 +38,16 @@ class ManifestElement {
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)
sprintf('Element %s missing', $elementName)
);
}
@@ -53,7 +59,7 @@ class ManifestElement {
if ($elementList->length === 0) {
throw new ManifestElementException(
\sprintf('Element(s) %s missing', $elementName)
sprintf('Element(s) %s missing', $elementName)
);
}

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;

View File

@@ -2,10 +2,11 @@
/*
* This file is part of PharIo\Manifest.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
* 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;