first commit - working

This commit is contained in:
2022-01-25 19:01:36 +00:00
commit 8f232d80d9
1361 changed files with 140207 additions and 0 deletions

View File

@ -0,0 +1,85 @@
<?php declare(strict_types = 1);
namespace PharIo\Version;
class PreReleaseSuffix {
private const valueScoreMap = [
'dev' => 0,
'a' => 1,
'alpha' => 1,
'b' => 2,
'beta' => 2,
'rc' => 3,
'p' => 4,
'patch' => 4,
];
/** @var string */
private $value;
/** @var int */
private $valueScore;
/** @var int */
private $number = 0;
/** @var string */
private $full;
/**
* @throws InvalidPreReleaseSuffixException
*/
public function __construct(string $value) {
$this->parseValue($value);
}
public function asString(): string {
return $this->full;
}
public function getValue(): string {
return $this->value;
}
public function getNumber(): ?int {
return $this->number;
}
public function isGreaterThan(PreReleaseSuffix $suffix): bool {
if ($this->valueScore > $suffix->valueScore) {
return true;
}
if ($this->valueScore < $suffix->valueScore) {
return false;
}
return $this->getNumber() > $suffix->getNumber();
}
private function mapValueToScore(string $value): int {
$value = \strtolower($value);
if (\array_key_exists($value, self::valueScoreMap)) {
return self::valueScoreMap[$value];
}
return 0;
}
private function parseValue(string $value): void {
$regex = '/-?((dev|beta|b|rc|alpha|a|patch|p)\.?(\d*)).*$/i';
if (\preg_match($regex, $value, $matches) !== 1) {
throw new InvalidPreReleaseSuffixException(\sprintf('Invalid label %s', $value));
}
$this->full = $matches[1];
$this->value = $matches[2];
if ($matches[3] !== '') {
$this->number = (int)$matches[3];
}
$this->valueScore = $this->mapValueToScore($matches[2]);
}
}

162
vendor/phar-io/version/src/Version.php vendored Normal file
View File

@ -0,0 +1,162 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class Version {
/** @var string */
private $originalVersionString;
/** @var VersionNumber */
private $major;
/** @var VersionNumber */
private $minor;
/** @var VersionNumber */
private $patch;
/** @var null|PreReleaseSuffix */
private $preReleaseSuffix;
public function __construct(string $versionString) {
$this->ensureVersionStringIsValid($versionString);
$this->originalVersionString = $versionString;
}
public function getPreReleaseSuffix(): PreReleaseSuffix {
if ($this->preReleaseSuffix === null) {
throw new NoPreReleaseSuffixException('No pre-release suffix set');
}
return $this->preReleaseSuffix;
}
public function getOriginalString(): string {
return $this->originalVersionString;
}
public function getVersionString(): string {
$str = \sprintf(
'%d.%d.%d',
$this->getMajor()->getValue() ?? 0,
$this->getMinor()->getValue() ?? 0,
$this->getPatch()->getValue() ?? 0
);
if (!$this->hasPreReleaseSuffix()) {
return $str;
}
return $str . '-' . $this->getPreReleaseSuffix()->asString();
}
public function hasPreReleaseSuffix(): bool {
return $this->preReleaseSuffix !== null;
}
public function equals(Version $other): bool {
return $this->getVersionString() === $other->getVersionString();
}
public function isGreaterThan(Version $version): bool {
if ($version->getMajor()->getValue() > $this->getMajor()->getValue()) {
return false;
}
if ($version->getMajor()->getValue() < $this->getMajor()->getValue()) {
return true;
}
if ($version->getMinor()->getValue() > $this->getMinor()->getValue()) {
return false;
}
if ($version->getMinor()->getValue() < $this->getMinor()->getValue()) {
return true;
}
if ($version->getPatch()->getValue() > $this->getPatch()->getValue()) {
return false;
}
if ($version->getPatch()->getValue() < $this->getPatch()->getValue()) {
return true;
}
if (!$version->hasPreReleaseSuffix() && !$this->hasPreReleaseSuffix()) {
return false;
}
if ($version->hasPreReleaseSuffix() && !$this->hasPreReleaseSuffix()) {
return true;
}
if (!$version->hasPreReleaseSuffix() && $this->hasPreReleaseSuffix()) {
return false;
}
return $this->getPreReleaseSuffix()->isGreaterThan($version->getPreReleaseSuffix());
}
public function getMajor(): VersionNumber {
return $this->major;
}
public function getMinor(): VersionNumber {
return $this->minor;
}
public function getPatch(): VersionNumber {
return $this->patch;
}
/**
* @param string[] $matches
*
* @throws InvalidPreReleaseSuffixException
*/
private function parseVersion(array $matches): void {
$this->major = new VersionNumber((int)$matches['Major']);
$this->minor = new VersionNumber((int)$matches['Minor']);
$this->patch = isset($matches['Patch']) ? new VersionNumber((int)$matches['Patch']) : new VersionNumber(0);
if (isset($matches['PreReleaseSuffix'])) {
$this->preReleaseSuffix = new PreReleaseSuffix($matches['PreReleaseSuffix']);
}
}
/**
* @param string $version
*
* @throws InvalidVersionException
*/
private function ensureVersionStringIsValid($version): void {
$regex = '/^v?
(?<Major>(0|(?:[1-9]\d*)))
\\.
(?<Minor>(0|(?:[1-9]\d*)))
(\\.
(?<Patch>(0|(?:[1-9]\d*)))
)?
(?:
-
(?<PreReleaseSuffix>(?:(dev|beta|b|rc|alpha|a|patch|p)\.?\d*))
)?
$/xi';
if (\preg_match($regex, $version, $matches) !== 1) {
throw new InvalidVersionException(
\sprintf("Version string '%s' does not follow SemVer semantics", $version)
);
}
$this->parseVersion($matches);
}
}

View File

@ -0,0 +1,115 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class VersionConstraintParser {
/**
* @throws UnsupportedVersionConstraintException
*/
public function parse(string $value): VersionConstraint {
if (\strpos($value, '||') !== false) {
return $this->handleOrGroup($value);
}
if (!\preg_match('/^[\^~*]?v?[\d.*]+(?:-.*)?$/i', $value)) {
throw new UnsupportedVersionConstraintException(
\sprintf('Version constraint %s is not supported.', $value)
);
}
switch ($value[0]) {
case '~':
return $this->handleTildeOperator($value);
case '^':
return $this->handleCaretOperator($value);
}
$constraint = new VersionConstraintValue($value);
if ($constraint->getMajor()->isAny()) {
return new AnyVersionConstraint();
}
if ($constraint->getMinor()->isAny()) {
return new SpecificMajorVersionConstraint(
$constraint->getVersionString(),
$constraint->getMajor()->getValue() ?? 0
);
}
if ($constraint->getPatch()->isAny()) {
return new SpecificMajorAndMinorVersionConstraint(
$constraint->getVersionString(),
$constraint->getMajor()->getValue() ?? 0,
$constraint->getMinor()->getValue() ?? 0
);
}
return new ExactVersionConstraint($constraint->getVersionString());
}
private function handleOrGroup(string $value): OrVersionConstraintGroup {
$constraints = [];
foreach (\explode('||', $value) as $groupSegment) {
$constraints[] = $this->parse(\trim($groupSegment));
}
return new OrVersionConstraintGroup($value, $constraints);
}
private function handleTildeOperator(string $value): AndVersionConstraintGroup {
$constraintValue = new VersionConstraintValue(\substr($value, 1));
if ($constraintValue->getPatch()->isAny()) {
return $this->handleCaretOperator($value);
}
$constraints = [
new GreaterThanOrEqualToVersionConstraint(
$value,
new Version(\substr($value, 1))
),
new SpecificMajorAndMinorVersionConstraint(
$value,
$constraintValue->getMajor()->getValue() ?? 0,
$constraintValue->getMinor()->getValue() ?? 0
)
];
return new AndVersionConstraintGroup($value, $constraints);
}
private function handleCaretOperator(string $value): AndVersionConstraintGroup {
$constraintValue = new VersionConstraintValue(\substr($value, 1));
$constraints = [
new GreaterThanOrEqualToVersionConstraint($value, new Version(\substr($value, 1)))
];
if ($constraintValue->getMajor()->getValue() === 0) {
$constraints[] = new SpecificMajorAndMinorVersionConstraint(
$value,
$constraintValue->getMajor()->getValue() ?? 0,
$constraintValue->getMinor()->getValue() ?? 0
);
} else {
$constraints[] = new SpecificMajorVersionConstraint(
$value,
$constraintValue->getMajor()->getValue() ?? 0
);
}
return new AndVersionConstraintGroup(
$value,
$constraints
);
}
}

View File

@ -0,0 +1,88 @@
<?php declare(strict_types = 1);
namespace PharIo\Version;
class VersionConstraintValue {
/** @var VersionNumber */
private $major;
/** @var VersionNumber */
private $minor;
/** @var VersionNumber */
private $patch;
/** @var string */
private $label = '';
/** @var string */
private $buildMetaData = '';
/** @var string */
private $versionString = '';
public function __construct(string $versionString) {
$this->versionString = $versionString;
$this->parseVersion($versionString);
}
public function getLabel(): string {
return $this->label;
}
public function getBuildMetaData(): string {
return $this->buildMetaData;
}
public function getVersionString(): string {
return $this->versionString;
}
public function getMajor(): VersionNumber {
return $this->major;
}
public function getMinor(): VersionNumber {
return $this->minor;
}
public function getPatch(): VersionNumber {
return $this->patch;
}
private function parseVersion(string $versionString): void {
$this->extractBuildMetaData($versionString);
$this->extractLabel($versionString);
$this->stripPotentialVPrefix($versionString);
$versionSegments = \explode('.', $versionString);
$this->major = new VersionNumber(\is_numeric($versionSegments[0]) ? (int)$versionSegments[0] : null);
$minorValue = isset($versionSegments[1]) && \is_numeric($versionSegments[1]) ? (int)$versionSegments[1] : null;
$patchValue = isset($versionSegments[2]) && \is_numeric($versionSegments[2]) ? (int)$versionSegments[2] : null;
$this->minor = new VersionNumber($minorValue);
$this->patch = new VersionNumber($patchValue);
}
private function extractBuildMetaData(string &$versionString): void {
if (\preg_match('/\+(.*)/', $versionString, $matches) === 1) {
$this->buildMetaData = $matches[1];
$versionString = \str_replace($matches[0], '', $versionString);
}
}
private function extractLabel(string &$versionString): void {
if (\preg_match('/-(.*)/', $versionString, $matches) === 1) {
$this->label = $matches[1];
$versionString = \str_replace($matches[0], '', $versionString);
}
}
private function stripPotentialVPrefix(string &$versionString): void {
if ($versionString[0] !== 'v') {
return;
}
$versionString = \substr($versionString, 1);
}
}

View File

@ -0,0 +1,28 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class VersionNumber {
/** @var ?int */
private $value;
public function __construct(?int $value) {
$this->value = $value;
}
public function isAny(): bool {
return $this->value === null;
}
public function getValue(): ?int {
return $this->value;
}
}

View File

@ -0,0 +1,23 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
abstract class AbstractVersionConstraint implements VersionConstraint {
/** @var string */
private $originalValue;
public function __construct(string $originalValue) {
$this->originalValue = $originalValue;
}
public function asString(): string {
return $this->originalValue;
}
}

View File

@ -0,0 +1,34 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class AndVersionConstraintGroup extends AbstractVersionConstraint {
/** @var VersionConstraint[] */
private $constraints = [];
/**
* @param VersionConstraint[] $constraints
*/
public function __construct(string $originalValue, array $constraints) {
parent::__construct($originalValue);
$this->constraints = $constraints;
}
public function complies(Version $version): bool {
foreach ($this->constraints as $constraint) {
if (!$constraint->complies($version)) {
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,20 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class AnyVersionConstraint implements VersionConstraint {
public function complies(Version $version): bool {
return true;
}
public function asString(): string {
return '*';
}
}

View File

@ -0,0 +1,16 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class ExactVersionConstraint extends AbstractVersionConstraint {
public function complies(Version $version): bool {
return $this->asString() === $version->getVersionString();
}
}

View File

@ -0,0 +1,26 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class GreaterThanOrEqualToVersionConstraint extends AbstractVersionConstraint {
/** @var Version */
private $minimalVersion;
public function __construct(string $originalValue, Version $minimalVersion) {
parent::__construct($originalValue);
$this->minimalVersion = $minimalVersion;
}
public function complies(Version $version): bool {
return $version->getVersionString() === $this->minimalVersion->getVersionString()
|| $version->isGreaterThan($this->minimalVersion);
}
}

View File

@ -0,0 +1,35 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class OrVersionConstraintGroup extends AbstractVersionConstraint {
/** @var VersionConstraint[] */
private $constraints = [];
/**
* @param string $originalValue
* @param VersionConstraint[] $constraints
*/
public function __construct($originalValue, array $constraints) {
parent::__construct($originalValue);
$this->constraints = $constraints;
}
public function complies(Version $version): bool {
foreach ($this->constraints as $constraint) {
if ($constraint->complies($version)) {
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,33 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class SpecificMajorAndMinorVersionConstraint extends AbstractVersionConstraint {
/** @var int */
private $major;
/** @var int */
private $minor;
public function __construct(string $originalValue, int $major, int $minor) {
parent::__construct($originalValue);
$this->major = $major;
$this->minor = $minor;
}
public function complies(Version $version): bool {
if ($version->getMajor()->getValue() !== $this->major) {
return false;
}
return $version->getMinor()->getValue() === $this->minor;
}
}

View File

@ -0,0 +1,25 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class SpecificMajorVersionConstraint extends AbstractVersionConstraint {
/** @var int */
private $major;
public function __construct(string $originalValue, int $major) {
parent::__construct($originalValue);
$this->major = $major;
}
public function complies(Version $version): bool {
return $version->getMajor()->getValue() === $this->major;
}
}

View File

@ -0,0 +1,16 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
interface VersionConstraint {
public function complies(Version $version): bool;
public function asString(): string;
}

View File

@ -0,0 +1,15 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use Throwable;
interface Exception extends Throwable {
}

View File

@ -0,0 +1,5 @@
<?php declare(strict_types = 1);
namespace PharIo\Version;
class InvalidPreReleaseSuffixException extends \Exception implements Exception {
}

View File

@ -0,0 +1,5 @@
<?php declare(strict_types = 1);
namespace PharIo\Version;
class InvalidVersionException extends \InvalidArgumentException implements Exception {
}

View File

@ -0,0 +1,5 @@
<?php declare(strict_types = 1);
namespace PharIo\Version;
class NoPreReleaseSuffixException extends \Exception implements Exception {
}

View File

@ -0,0 +1,13 @@
<?php declare(strict_types = 1);
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
final class UnsupportedVersionConstraintException extends \RuntimeException implements Exception {
}