vendor and env first commit
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Alessandro Lai
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "jean85/pretty-package-versions",
|
||||
"description": "A library to get pretty versions strings of installed dependencies",
|
||||
"type": "library",
|
||||
"require": {
|
||||
"php": "^7.1|^8.0",
|
||||
"composer-runtime-api": "^2.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.2",
|
||||
"jean85/composer-provided-replaced-stub-package": "^1.0",
|
||||
"phpstan/phpstan": "^1.4",
|
||||
"phpunit/phpunit": "^7.5|^8.5|^9.4",
|
||||
"vimeo/psalm": "^4.3"
|
||||
},
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alessandro Lai",
|
||||
"email": "alessandro.lai85@gmail.com"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Jean85/pretty-package-versions/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"package",
|
||||
"versions",
|
||||
"composer",
|
||||
"release"
|
||||
],
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Jean85\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests"
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jean85\Exception;
|
||||
|
||||
class ProvidedPackageException extends \Exception implements VersionMissingExceptionInterface
|
||||
{
|
||||
public static function create(string $packageName): VersionMissingExceptionInterface
|
||||
{
|
||||
return new self('Cannot retrieve a version for package ' . $packageName . ' since it is provided, probably a metapackage');
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jean85\Exception;
|
||||
|
||||
class ReplacedPackageException extends \Exception implements VersionMissingExceptionInterface
|
||||
{
|
||||
public static function create(string $packageName): VersionMissingExceptionInterface
|
||||
{
|
||||
return new self('Cannot retrieve a version for package ' . $packageName . ' since it is replaced by some other package');
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jean85\Exception;
|
||||
|
||||
interface VersionMissingExceptionInterface extends \Throwable
|
||||
{
|
||||
public static function create(string $packageName): self;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jean85;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Jean85\Exception\ProvidedPackageException;
|
||||
use Jean85\Exception\ReplacedPackageException;
|
||||
use Jean85\Exception\VersionMissingExceptionInterface;
|
||||
|
||||
class PrettyVersions
|
||||
{
|
||||
/**
|
||||
* @throws VersionMissingExceptionInterface When a package is provided ({@see ProvidedPackageException}) or replaced ({@see ReplacedPackageException})
|
||||
*/
|
||||
public static function getVersion(string $packageName): Version
|
||||
{
|
||||
self::checkProvidedPackages($packageName);
|
||||
|
||||
self::checkReplacedPackages($packageName);
|
||||
|
||||
return new Version(
|
||||
$packageName,
|
||||
InstalledVersions::getPrettyVersion($packageName),
|
||||
InstalledVersions::getReference($packageName)
|
||||
);
|
||||
}
|
||||
|
||||
public static function getRootPackageName(): string
|
||||
{
|
||||
return InstalledVersions::getRootPackage()['name'];
|
||||
}
|
||||
|
||||
public static function getRootPackageVersion(): Version
|
||||
{
|
||||
return new Version(
|
||||
self::getRootPackageName(),
|
||||
InstalledVersions::getRootPackage()['pretty_version'],
|
||||
InstalledVersions::getRootPackage()['reference']
|
||||
);
|
||||
}
|
||||
|
||||
protected static function checkProvidedPackages(string $packageName): void
|
||||
{
|
||||
if (! method_exists(InstalledVersions::class, 'getAllRawData')) {
|
||||
if (isset(InstalledVersions::getRawData()['versions'][$packageName]['provided'])) {
|
||||
throw ProvidedPackageException::create($packageName);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (InstalledVersions::getAllRawData() as $installed) {
|
||||
if (isset($installed['versions'][$packageName]['provided'])) {
|
||||
throw ProvidedPackageException::create($packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function checkReplacedPackages(string $packageName): void
|
||||
{
|
||||
if (! method_exists(InstalledVersions::class, 'getAllRawData')) {
|
||||
if (isset(InstalledVersions::getRawData()['versions'][$packageName]['replaced'])) {
|
||||
throw ReplacedPackageException::create($packageName);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (InstalledVersions::getAllRawData() as $installed) {
|
||||
if (isset($installed['versions'][$packageName]['replaced'])) {
|
||||
throw ReplacedPackageException::create($packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jean85;
|
||||
|
||||
class Version
|
||||
{
|
||||
private const SHORT_COMMIT_LENGTH = 7;
|
||||
|
||||
/** @var string */
|
||||
private $packageName;
|
||||
|
||||
/** @var string */
|
||||
private $prettyVersion;
|
||||
|
||||
/** @var string */
|
||||
private $reference;
|
||||
|
||||
/** @var bool */
|
||||
private $versionIsTagged;
|
||||
|
||||
public const NO_VERSION_TEXT = '{no version}';
|
||||
public const NO_REFERENCE_TEXT = '{no reference}';
|
||||
|
||||
public function __construct(string $packageName, ?string $prettyVersion = null, ?string $reference = null)
|
||||
{
|
||||
$this->packageName = $packageName;
|
||||
$this->prettyVersion = $prettyVersion ?? self::NO_VERSION_TEXT;
|
||||
$this->reference = $reference ?? self::NO_REFERENCE_TEXT;
|
||||
$this->versionIsTagged = preg_match('/[^v\d.]/', $this->getShortVersion()) === 0;
|
||||
}
|
||||
|
||||
public function getPrettyVersion(): string
|
||||
{
|
||||
if ($this->versionIsTagged) {
|
||||
return $this->prettyVersion;
|
||||
}
|
||||
|
||||
return $this->getVersionWithShortReference();
|
||||
}
|
||||
|
||||
public function getFullVersion(): string
|
||||
{
|
||||
return $this->prettyVersion . '@' . $this->getReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function getVersionWithShortCommit(): string
|
||||
{
|
||||
return $this->getVersionWithShortReference();
|
||||
}
|
||||
|
||||
public function getVersionWithShortReference(): string
|
||||
{
|
||||
return $this->prettyVersion . '@' . $this->getShortReference();
|
||||
}
|
||||
|
||||
public function getPackageName(): string
|
||||
{
|
||||
return $this->packageName;
|
||||
}
|
||||
|
||||
public function getShortVersion(): string
|
||||
{
|
||||
return $this->prettyVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function getCommitHash(): string
|
||||
{
|
||||
return $this->getReference();
|
||||
}
|
||||
|
||||
public function getReference(): string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function getShortCommitHash(): string
|
||||
{
|
||||
return $this->getShortReference();
|
||||
}
|
||||
|
||||
public function getShortReference(): string
|
||||
{
|
||||
return substr($this->reference, 0, self::SHORT_COMMIT_LENGTH);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getPrettyVersion();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user