Author.php 0000644 00000002430 15152066104 0006516 0 ustar 00 <?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;
}
}
PhpExtensionRequirement.php 0000644 00000001252 15152066104 0012122 0 ustar 00 <?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;
}
}
Manifest.php 0000644 00000005055 15152066104 0007030 0 ustar 00 <?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);
}
}
Library.php 0000644 00000000760 15152066104 0006664 0 ustar 00 <?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;
}
}
ApplicationName.php 0000644 00000002234 15152066104 0010322 0 ustar 00 <?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
);
}
}
}
BundledComponent.php 0000644 00000001510 15152066104 0010512 0 ustar 00 <?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;
}
}
Type.php 0000644 00000002243 15152066104 0006177 0 ustar 00 <?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;
}
}
CopyrightInformation.php 0000644 00000001534 15152066104 0011436 0 ustar 00 <?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;
}
}
BundledComponentCollection.php 0000644 00000002242 15152066104 0012531 0 ustar 00 <?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);
}
}
License.php 0000644 00000001374 15152066104 0006644 0 ustar 00 <?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;
}
}
AuthorCollectionIterator.php 0000644 00000002205 15152066104 0012244 0 ustar 00 <?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++;
}
}
Email.php 0000644 00000001620 15152066104 0006303 0 ustar 00 <?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;
}
}
}
Url.php 0000644 00000001653 15152066104 0006024 0 ustar 00 <?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;
}
}
}
Application.php 0000644 00000000770 15152066104 0007524 0 ustar 00 <?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;
}
}
RequirementCollection.php 0000644 00000002134 15152066104 0011571 0 ustar 00 <?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);
}
}
RequirementCollectionIterator.php 0000644 00000002301 15152066104 0013277 0 ustar 00 <?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++;
}
}
Requirement.php 0000644 00000000650 15152066104 0007556 0 ustar 00 <?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 {
}
AuthorCollection.php 0000644 00000002026 15152066104 0010533 0 ustar 00 <?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);
}
}
Extension.php 0000644 00000002626 15152066104 0007237 0 ustar 00 <?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);
}
}
BundledComponentCollectionIterator.php 0000644 00000002375 15152066104 0014252 0 ustar 00 <?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++;
}
}
PhpVersionRequirement.php 0000644 00000001444 15152066104 0011576 0 ustar 00 <?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;
}
}