Added Laravel project

This commit is contained in:
2017-09-17 00:35:10 +02:00
parent a3c19304d5
commit ecf605b8f5
6246 changed files with 682270 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
<?php
/*
* 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 = '';
/**
* @param string $originalValue
*/
public function __construct($originalValue) {
$this->originalValue = $originalValue;
}
/**
* @return string
*/
public function asString() {
return $this->originalValue;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* 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 string $originalValue
* @param VersionConstraint[] $constraints
*/
public function __construct($originalValue, array $constraints) {
parent::__construct($originalValue);
$this->constraints = $constraints;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
foreach ($this->constraints as $constraint) {
if (!$constraint->complies($version)) {
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*
* 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 {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return true;
}
/**
* @return string
*/
public function asString() {
return '*';
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* 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 {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $this->asString() == $version->getVersionString();
}
}

View File

@@ -0,0 +1,14 @@
<?php
/*
* 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 Exception {
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* 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;
/**
* @param string $originalValue
* @param Version $minimalVersion
*/
public function __construct($originalValue, Version $minimalVersion) {
parent::__construct($originalValue);
$this->minimalVersion = $minimalVersion;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $version->getVersionString() == $this->minimalVersion->getVersionString() ||
$version->isGreaterThan($this->minimalVersion);
}
}

View File

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

View File

@@ -0,0 +1,43 @@
<?php
/*
* 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;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
foreach ($this->constraints as $constraint) {
if ($constraint->complies($version)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace PharIo\Version;
class PreReleaseSuffix
{
/**
* @var string
*/
private $value;
/**
* @var int
*/
private $number;
/**
* @param string $value
* @param int|null $number
*/
public function __construct($value, $number = null)
{
$this->value = $value;
$this->number = $number;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @return int|null
*/
public function getNumber()
{
return $this->number;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* 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 = 0;
/**
* @var int
*/
private $minor = 0;
/**
* @param string $originalValue
* @param int $major
* @param int $minor
*/
public function __construct($originalValue, $major, $minor) {
parent::__construct($originalValue);
$this->major = $major;
$this->minor = $minor;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
if ($version->getMajor()->getValue() != $this->major) {
return false;
}
return $version->getMinor()->getValue() == $this->minor;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*
* 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 = 0;
/**
* @param string $originalValue
* @param int $major
*/
public function __construct($originalValue, $major) {
parent::__construct($originalValue);
$this->major = $major;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $version->getMajor()->getValue() == $this->major;
}
}

View File

@@ -0,0 +1,14 @@
<?php
/*
* 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 {
}

View File

@@ -0,0 +1,162 @@
<?php
/*
* 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 VersionNumber
*/
private $major;
/**
* @var VersionNumber
*/
private $minor;
/**
* @var VersionNumber
*/
private $patch;
/**
* @var PreReleaseSuffix
*/
private $preReleaseSuffix;
/**
* @var string
*/
private $versionString = '';
/**
* @param string $versionString
*/
public function __construct($versionString) {
$this->ensureVersionStringIsValid($versionString);
$this->versionString = $versionString;
}
/**
* @param array $matches
*/
private function parseVersion(array $matches) {
$this->major = new VersionNumber($matches['Major']);
$this->minor = new VersionNumber($matches['Minor']);
$this->patch = isset($matches['Patch']) ? new VersionNumber($matches['Patch']) : new VersionNumber(null);
if (isset($matches['ReleaseType'])) {
$preReleaseNumber = isset($matches['ReleaseTypeCount']) ? (int) $matches['ReleaseTypeCount'] : null;
$this->preReleaseSuffix = new PreReleaseSuffix($matches['ReleaseType'], $preReleaseNumber);
}
}
/**
* @return PreReleaseSuffix
*/
public function getPreReleaseSuffix()
{
return $this->preReleaseSuffix;
}
/**
* @return string
*/
public function getVersionString() {
return $this->versionString;
}
/**
* @param Version $version
*
* @return bool
*/
public function isGreaterThan(Version $version) {
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;
}
return false;
}
/**
* @return VersionNumber
*/
public function getMajor() {
return $this->major;
}
/**
* @return VersionNumber
*/
public function getMinor() {
return $this->minor;
}
/**
* @return VersionNumber
*/
public function getPatch() {
return $this->patch;
}
/**
* @param string $version
*
* @throws InvalidVersionException
*/
private function ensureVersionStringIsValid($version) {
$regex = '/^v?
(?<Major>(0|(?:[1-9][0-9]*)))
\\.
(?<Minor>(0|(?:[1-9][0-9]*)))
(\\.
(?<Patch>(0|(?:[1-9][0-9]*)))
)?
(?:
-
(?<ReleaseType>(?:(dev|beta|b|RC|alpha|a|patch|p)))
(?:
(?<ReleaseTypeCount>[0-9])
)?
)?
$/x';
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,26 @@
<?php
/*
* 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 {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version);
/**
* @return string
*/
public function asString();
}

View File

@@ -0,0 +1,122 @@
<?php
/*
* 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 {
/**
* @param string $value
*
* @return VersionConstraint
*
* @throws UnsupportedVersionConstraintException
*/
public function parse($value) {
if (strpos($value, '||') !== false) {
return $this->handleOrGroup($value);
}
if (!preg_match('/^[\^~\*]?[\d.\*]+$/', $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);
}
$version = new VersionConstraintValue($value);
if ($version->getMajor()->isAny()) {
return new AnyVersionConstraint();
}
if ($version->getMinor()->isAny()) {
return new SpecificMajorVersionConstraint(
$value,
$version->getMajor()->getValue()
);
}
if ($version->getPatch()->isAny()) {
return new SpecificMajorAndMinorVersionConstraint(
$value,
$version->getMajor()->getValue(),
$version->getMinor()->getValue()
);
}
return new ExactVersionConstraint($value);
}
/**
* @param $value
*
* @return OrVersionConstraintGroup
*/
private function handleOrGroup($value) {
$constraints = [];
foreach (explode('||', $value) as $groupSegment) {
$constraints[] = $this->parse(trim($groupSegment));
}
return new OrVersionConstraintGroup($value, $constraints);
}
/**
* @param string $value
*
* @return AndVersionConstraintGroup
*/
private function handleTildeOperator($value) {
$version = new Version(substr($value, 1));
$constraints = [
new GreaterThanOrEqualToVersionConstraint($value, $version)
];
if ($version->getPatch()->isAny()) {
$constraints[] = new SpecificMajorVersionConstraint(
$value,
$version->getMajor()->getValue()
);
} else {
$constraints[] = new SpecificMajorAndMinorVersionConstraint(
$value,
$version->getMajor()->getValue(),
$version->getMinor()->getValue()
);
}
return new AndVersionConstraintGroup($value, $constraints);
}
/**
* @param string $value
*
* @return AndVersionConstraintGroup
*/
private function handleCaretOperator($value) {
$version = new Version(substr($value, 1));
return new AndVersionConstraintGroup(
$value,
[
new GreaterThanOrEqualToVersionConstraint($value, $version),
new SpecificMajorVersionConstraint($value, $version->getMajor()->getValue())
]
);
}
}

View File

@@ -0,0 +1,123 @@
<?php
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 = '';
/**
* @param string $versionString
*/
public function __construct($versionString) {
$this->versionString = $versionString;
$this->parseVersion($versionString);
}
/**
* @param $versionString
*/
private function parseVersion($versionString) {
$this->extractBuildMetaData($versionString);
$this->extractLabel($versionString);
$versionSegments = explode('.', $versionString);
$this->major = new VersionNumber($versionSegments[0]);
$minorValue = isset($versionSegments[1]) ? $versionSegments[1] : null;
$patchValue = isset($versionSegments[2]) ? $versionSegments[2] : null;
$this->minor = new VersionNumber($minorValue);
$this->patch = new VersionNumber($patchValue);
}
/**
* @param string $versionString
*/
private function extractBuildMetaData(&$versionString) {
if (preg_match('/\+(.*)/', $versionString, $matches) == 1) {
$this->buildMetaData = $matches[1];
$versionString = str_replace($matches[0], '', $versionString);
}
}
/**
* @param string $versionString
*/
private function extractLabel(&$versionString) {
if (preg_match('/\-(.*)/', $versionString, $matches) == 1) {
$this->label = $matches[1];
$versionString = str_replace($matches[0], '', $versionString);
}
}
/**
* @return string
*/
public function getLabel() {
return $this->label;
}
/**
* @return string
*/
public function getBuildMetaData() {
return $this->buildMetaData;
}
/**
* @return string
*/
public function getVersionString() {
return $this->versionString;
}
/**
* @return VersionNumber
*/
public function getMajor() {
return $this->major;
}
/**
* @return VersionNumber
*/
public function getMinor() {
return $this->minor;
}
/**
* @return VersionNumber
*/
public function getPatch() {
return $this->patch;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* 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;
/**
* @param mixed $value
*/
public function __construct($value) {
if (is_numeric($value)) {
$this->value = $value;
}
}
/**
* @return bool
*/
public function isAny() {
return $this->value === null;
}
/**
* @return int
*/
public function getValue() {
return $this->value;
}
}