PK h^GMµ{üÈu u README.mdnu W+A„¶ # Package Versions
> This is a backport of `ocramius/package-versions` that support php 5.6, while `ocramius/package-versions` only support php 7+.
>
It's a more recent version of samsonasik/package-versions
This utility provides quick and easy access to version information of composer dependencies.
This information is derived from the ```composer.lock``` file which is (re)generated during ```composer install``` or ```composer update```.
```php
$version = \PackageVersions\Versions::getVersion('muglug/package-versions');
var_dump($version); // 1.0.0@0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
$version = \PackageVersions\Versions::getShortVersion('muglug/package-versions');
var_dump($version); // 1.0.0
$version = \PackageVersions\Versions::getMajorVersion('muglug/package-versions');
var_dump($version); // 1
```
[![Build Status](https://travis-ci.org/muglug/PackageVersions.svg?branch=master)](https://travis-ci.org/muglug/PackageVersions)
[![Downloads](https://img.shields.io/packagist/dt/muglug/package-versions.svg)](https://packagist.org/packages/muglug/package-versions)
[![Packagist](https://img.shields.io/packagist/v/muglug/package-versions.svg)](https://packagist.org/packages/muglug/package-versions)
[![Packagist Pre Release](https://img.shields.io/packagist/vpre/muglug/package-versions.svg)](https://packagist.org/packages/muglug/package-versions)
### Installation
```sh
composer require muglug/package-versions
```
It is suggested that you use a optimized composer autoloader in order to prevent
autoload I/O when accessing the `PackageVersions\Versions` API:
Therefore you should use `optimize-autoloader: true` in your composer.json:
```
...
"config": {
"optimize-autoloader": true
},
...
```
see https://getcomposer.org/doc/06-config.md#optimize-autoloader
In case you manually generate your autoloader via the CLI use the `--optimize` flag:
```sh
composer dump-autoload --optimize
```
### Use-cases
This repository implements `PackageVersions\Versions::getVersion()` in such a way that no IO
happens when calling it, because the list of package versions is compiled during composer
installation.
This is especially useful when you want to generate assets/code/artifacts that are computed from
the current version of a certain dependency. Doing so at runtime by checking the installed
version of a package would be too expensive, and this package mitigates that.
PK h^GMmN`S^ ^ CONTRIBUTING.mdnu W+A„¶ ---
title: Contributing
---
# Contributing
* Coding standard for the project is [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
* The project will follow strict [object calisthenics](http://www.slideshare.net/guilhermeblanco/object-calisthenics-applied-to-php)
* Any contribution must provide tests for additional introduced conditions
* Any un-confirmed issue needs a failing test case before being accepted
* Pull requests must be sent from a new hotfix/feature branch, not from `master`.
## Installation
To install the project and run the tests, you need to clone it first:
```sh
$ git clone git://github.com/Ocramius/PackageVersions.git
```
You will then need to run a composer installation:
```sh
$ cd PackageVersions
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar update
```
## Testing
The PHPUnit version to be used is the one installed as a dev- dependency via composer:
```sh
$ ./vendor/bin/phpunit
```
Accepted coverage for new contributions is 80%. Any contribution not satisfying this requirement
won't be merged.
PK h^GM³¾Ì^Ý
Ý
( src/PackageVersions/FallbackVersions.phpnu W+A„¶ $package['version'] . '@' . (
isset($package['source']['reference'])
? $package['source']['reference']
: (isset($package['dist']['reference']) ? $package['dist']['reference'] : '')
);
}
yield 'unknown/root-package@UNKNOWN';
}
}
PK h^GM™ØPi³ ³ ! src/PackageVersions/Installer.phpnu W+A„¶ 'dumpVersionsClass',
ScriptEvents::POST_UPDATE_CMD => 'dumpVersionsClass',
];
}
/**
* @param Event $composerEvent
*
* @return void
*
* @throws \RuntimeException
*/
public static function dumpVersionsClass(Event $composerEvent)
{
$composer = $composerEvent->getComposer();
$versions = iterator_to_array(self::getVersions($composer->getLocker(), $composer->getPackage()));
if (!array_key_exists('muglug/package-versions-56', $versions)) {
//plugin must be globally installed - we only want to generate versions for projects which specifically
//require muglug/package-versions
return;
}
self::writeVersionClassToFile(self::generateVersionsClass($versions), $composer, $composerEvent->getIO());
}
private static function generateVersionsClass(array $versions)
{
return sprintf(
self::$generatedClassTemplate,
'fin' . 'al ' . 'cla' . 'ss ' . 'Versions', // note: workaround for regex-based code parsers :-(
var_export($versions, true)
);
}
/**
* @param string $versionClassSource
* @param Composer $composer
* @param IOInterface $io
*
* @return void
*
* @throws \RuntimeException
*/
private static function writeVersionClassToFile($versionClassSource, Composer $composer, IOInterface $io)
{
$installPath = self::locateRootPackageInstallPath($composer->getConfig(), $composer->getPackage())
. '/src/PackageVersions/Versions.php';
if (! file_exists(dirname($installPath))) {
$io->write('muglug/package-versions-56: Package not found (probably scheduled for removal); generation of version class skipped.');
return;
}
$io->write('muglug/package-versions-56: Generating version class...');
file_put_contents($installPath, $versionClassSource);
chmod($installPath, 0664);
$io->write('muglug/package-versions-56: ...done generating version class');
}
/**
* @param Config $composerConfig
* @param RootPackageInterface $rootPackage
*
* @return string
*
* @throws \RuntimeException
*/
private static function locateRootPackageInstallPath(
Config $composerConfig,
RootPackageInterface $rootPackage
) {
if ('muglug/package-versions-56' === self::getRootPackageAlias($rootPackage)->getName()) {
return dirname($composerConfig->get('vendor-dir'));
}
return $composerConfig->get('vendor-dir') . '/muglug/package-versions-56';
}
private static function getRootPackageAlias(RootPackageInterface $rootPackage)
{
$package = $rootPackage;
while ($package instanceof AliasPackage) {
$package = $package->getAliasOf();
}
return $package;
}
/**
* @param Locker $locker
* @param RootPackageInterface $rootPackage
*
* @return \Generator|\string[]
*/
private static function getVersions(Locker $locker, RootPackageInterface $rootPackage)
{
$lockData = $locker->getLockData();
$lockData['packages-dev'] = isset($lockData['packages-dev']) ? $lockData['packages-dev'] : [];
foreach (array_merge($lockData['packages'], $lockData['packages-dev']) as $package) {
yield $package['name'] => $package['version'] . '@' . (
isset($package['source']['reference'])
? $package['source']['reference']
: (isset($package['dist']['reference']) ? $package['dist']['reference'] : '')
);
}
yield $rootPackage->getName() => $rootPackage->getVersion() . '@' . $rootPackage->getSourceReference();
}
}
PK h^GMfnæx£ £ src/PackageVersions/Versions.phpnu W+A„¶ '1.0.9@36344aeffdc37711335563e6108cda86566432a6',
'composer/composer' => '1.5.2@c639623fa2178b404ed4bab80f0d1263853fa4ae',
'composer/semver' => '1.4.2@c7cb9a2095a074d131b65a8a0cd294479d785573',
'composer/spdx-licenses' => '1.1.6@2603a0d7ddc00a015deb576fa5297ca43dee6b1c',
'doctrine/instantiator' => '1.1.0@185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda',
'justinrainbow/json-schema' => '5.2.6@d283e11b6e14c6f4664cf080415c4341293e5bbd',
'myclabs/deep-copy' => '1.7.0@3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e',
'phpdocumentor/reflection-common' => '1.0.1@21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6',
'phpdocumentor/reflection-docblock' => '4.1.1@2d3d238c433cf69caeb4842e97a3223a116f94b2',
'phpdocumentor/type-resolver' => '0.4.0@9c977708995954784726e25d0cd1dddf4e65b0f7',
'phpspec/prophecy' => 'v1.7.2@c9b8c6088acd19d769d4cc0ffa60a9fe34344bd6',
'phpunit/php-code-coverage' => '4.0.8@ef7b2f56815df854e66ceaee8ebe9393ae36a40d',
'phpunit/php-file-iterator' => '1.4.2@3cc8f69b3028d0f96a9078e6295d86e9bf019be5',
'phpunit/php-text-template' => '1.2.1@31f8b717e51d9a2afca6c9f046f5d69fc27c8686',
'phpunit/php-timer' => '1.0.9@3dcf38ca72b158baf0bc245e9184d3fdffa9c46f',
'phpunit/php-token-stream' => '2.0.1@9a02332089ac48e704c70f6cefed30c224e3c0b0',
'phpunit/phpunit' => '5.7.23@78532d5269d984660080d8e0f4c99c5c2ea65ffe',
'phpunit/phpunit-mock-objects' => '3.4.4@a23b761686d50a560cc56233b9ecf49597cc9118',
'psr/log' => '1.0.2@4ebe3a8bf773a19edfe0a84b6585ba3d401b724d',
'sebastian/code-unit-reverse-lookup' => '1.0.1@4419fcdb5eabb9caa61a27c7a1db532a6b55dd18',
'sebastian/comparator' => '1.2.4@2b7424b55f5047b47ac6e5ccb20b2aea4011d9be',
'sebastian/diff' => '1.4.3@7f066a26a962dbe58ddea9f72a4e82874a3975a4',
'sebastian/environment' => '2.0.0@5795ffe5dc5b02460c3e34222fee8cbe245d8fac',
'sebastian/exporter' => '2.0.0@ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4',
'sebastian/global-state' => '1.1.1@bc37d50fea7d017d3d340f230811c9f1d7280af4',
'sebastian/object-enumerator' => '2.0.1@1311872ac850040a79c3c058bea3e22d0f09cbb7',
'sebastian/recursion-context' => '2.0.0@2c3ba150cbec723aa057506e73a8d33bdb286c9a',
'sebastian/resource-operations' => '1.0.0@ce990bb21759f94aeafd30209e8cfcdfa8bc3f52',
'sebastian/version' => '2.0.1@99732be0ddb3361e16ad77b68ba41efc8e979019',
'seld/cli-prompt' => '1.0.3@a19a7376a4689d4d94cab66ab4f3c816019ba8dd',
'seld/jsonlint' => '1.6.1@50d63f2858d87c4738d5b76a7dcbb99fa8cf7c77',
'seld/phar-utils' => '1.0.1@7009b5139491975ef6486545a39f3e6dad5ac30a',
'symfony/console' => 'v3.3.12@099302cc53e57cbb7414fd9f3ace40e5e2767c0b',
'symfony/debug' => 'v3.3.12@74557880e2846b5c84029faa96b834da37e29810',
'symfony/filesystem' => 'v3.3.12@77db266766b54db3ee982fe51868328b887ce15c',
'symfony/finder' => 'v3.3.12@138af5ec075d4b1d1bd19de08c38a34bb2d7d880',
'symfony/polyfill-mbstring' => 'v1.6.0@2ec8b39c38cb16674bbf3fea2b6ce5bf117e1296',
'symfony/process' => 'v3.3.12@a56a3989fb762d7b19a0cf8e7693ee99a6ffb78d',
'symfony/yaml' => 'v3.3.12@0938408c4faa518d95230deabb5f595bf0de31b9',
'webmozart/assert' => '1.2.0@2db61e59ff05fe5126d152bd0655c9ea113e550f',
'muglug/package-versions-56' => '2.0.9999999.9999999-dev@92b35cd2e5b58d9279fadb426d642ec9883b8b8d',
);
private function __construct()
{
}
/**
* @throws \OutOfBoundsException if a version cannot be located
*/
public static function getVersion($packageName)
{
$selfVersion = self::$VERSIONS;
if (! isset($selfVersion[$packageName])) {
throw new \OutOfBoundsException(
'Required package "' . $packageName . '" is not installed: cannot detect its version'
);
}
return $selfVersion[$packageName];
}
/**
* @throws \OutOfBoundsException if a version cannot be located
*/
public static function getShortVersion($packageName)
{
return explode('@', static::getVersion($packageName))[0];
}
/**
* @throws \OutOfBoundsException if a version cannot be located
*/
public static function getMajorVersion($packageName)
{
return explode('.', static::getShortVersion($packageName))[0];
}
}
PK h^GMm
Ñyé é CHANGELOG.mdnu W+A„¶ # CHANGELOG
## 1.1.3 - 2017-09-06
This release fixes a bug that caused PackageVersions to prevent
the `composer remove` and `composer update` commands to fail when
this package is removed.
In addition to that, mutation testing has been added to the suite,
ensuring that the package is accurately and extensively tested.
Total issues resolved: **3**
- [40: Mutation testing, PHP 7.1 testing](https://github.com/Ocramius/PackageVersions/pull/40) thanks to @Ocramius
- [41: Removing this package on install results in file access error](https://github.com/Ocramius/PackageVersions/issues/41) thanks to @Xerkus
- [46: #41 Avoid issues when the package is scheduled for removal](https://github.com/Ocramius/PackageVersions/pull/46) thanks to @Jean85
## 1.1.2 - 2016-12-30
This release fixes a bug that caused PackageVersions to be enabled
even when it was part of a globally installed package.
Total issues resolved: **3**
- [35: remove all temp directories](https://github.com/Ocramius/PackageVersions/pull/35)
- [38: Interferes with other projects when installed globally](https://github.com/Ocramius/PackageVersions/issues/38)
- [39: Ignore the global plugin when updating local projects](https://github.com/Ocramius/PackageVersions/pull/39)
## 1.1.1 - 2016-07-25
This release removes the [`"files"`](https://getcomposer.org/doc/04-schema.md#files) directive from
[`composer.json`](https://github.com/Ocramius/PackageVersions/commit/86f2636f7c5e7b56fa035fa3826d5fcf80b6dc72),
as it is no longer needed for `composer install --classmap-authoritative`.
Also, that directive was causing issues with HHVM installations, since
PackageVersions is not compatible with it.
Total issues resolved: **1**
- [34: Fatal error during travis build after update to 1.1.0](https://github.com/Ocramius/PackageVersions/issues/34)
## 1.1.0 - 2016-07-22
This release introduces support for running `composer install --classmap-authoritative`
and `composer install --no-scripts`. Please note that performance
while using these modes may be degraded, but the package will
still work.
Additionally, the package was tuned to prevent the plugin from
running twice at installation.
Total issues resolved: **10**
- [18: Fails when using composer install --no-scripts](https://github.com/Ocramius/PackageVersions/issues/18)
- [20: CS (spacing)](https://github.com/Ocramius/PackageVersions/pull/20)
- [22: Document the way the require-dev section is treated](https://github.com/Ocramius/PackageVersions/issues/22)
- [23: Underline that composer.lock is used as source of information](https://github.com/Ocramius/PackageVersions/pull/23)
- [27: Fix incompatibility with --classmap-authoritative](https://github.com/Ocramius/PackageVersions/pull/27)
- [29: mention optimize-autoloader composer.json config option in README](https://github.com/Ocramius/PackageVersions/pull/29)
- [30: The version class is generated twice during composer update](https://github.com/Ocramius/PackageVersions/issues/30)
- [31: Remove double registration of the event listeners](https://github.com/Ocramius/PackageVersions/pull/31)
- [32: Update the usage of mock APIs to use the new API](https://github.com/Ocramius/PackageVersions/pull/32)
- [33: Fix for #18 - support running with --no-scripts flag](https://github.com/Ocramius/PackageVersions/pull/33)
## 1.0.4 - 2016-04-23
This release includes a fix/workaround for composer/composer#5237,
which causes `ocramius/package-versions` to sometimes generate a
`Versions` class with malformed name (something like
`Versions_composer_tmp0`) when running `composer require `.
Total issues resolved: **2**
- [16: Workaround for composer/composer#5237 - class parsing](https://github.com/Ocramius/PackageVersions/pull/16)
- [17: Weird Class name being generated](https://github.com/Ocramius/PackageVersions/issues/17)
## 1.0.3 - 2016-02-26
This release fixes an issue related to concurrent autoloader
re-generation caused by multiple composer plugins being installed.
The issue was solved by removing autoloader re-generation from this
package, but it may still affect other packages.
It is now recommended that you run `composer dump-autoload --optimize`
after installation when using this particular package.
Please note that `composer (install|update) -o` is not sufficient
to avoid autoload overhead when using this particular package.
Total issues resolved: **1**
- [15: Remove autoload re-dump optimization](https://github.com/Ocramius/PackageVersions/pull/15)
## 1.0.2 - 2016-02-24
This release fixes issues related to installing the component without
any dev dependencies or with packages that don't have a source or dist
reference, which is usual with packages defined directly in the
`composer.json`.
Total issues resolved: **3**
- [11: fix composer install --no-dev PHP7](https://github.com/Ocramius/PackageVersions/pull/11)
- [12: Packages don't always have a source/reference](https://github.com/Ocramius/PackageVersions/issues/12)
- [13: Fix #12 - support dist and missing package version references](https://github.com/Ocramius/PackageVersions/pull/13)
## 1.0.1 - 2016-02-01
This release fixes an issue related with composer updates to
already installed versions.
Using `composer require` within a package that already used
`ocramius/package-versions` caused the installation to be unable
to write the `PackageVersions\Versions` class to a file.
Total issues resolved: **6**
- [2: remove unused use statement](https://github.com/Ocramius/PackageVersions/pull/2)
- [3: Remove useless files from dist package](https://github.com/Ocramius/PackageVersions/pull/3)
- [5: failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly](https://github.com/Ocramius/PackageVersions/issues/5)
- [6: Fix/#5 use composer vendor dir](https://github.com/Ocramius/PackageVersions/pull/6)
- [7: Hotfix - #5 generate package versions also when in phar context](https://github.com/Ocramius/PackageVersions/pull/7)
- [8: Versions class should be ignored by VCS, as it is an install-time artifact](https://github.com/Ocramius/PackageVersions/pull/8)
PK h^GMôô‚! ! LICENSEnu W+A„¶ Copyright (c) 2016 Marco Pivetta
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.
PK h^GMFoã £
composer.jsonnu W+A„¶ {
"name": "muglug/package-versions-56",
"description": "A backport of ocramius/package-versions that supports php ^5.6. Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
"type": "composer-plugin",
"license": "MIT",
"authors": [
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
},
{
"name": "Abdul Malik Ikhsan",
"email": "samsonasik@gmail.com"
},
{
"name": "Matt Brown",
"email": "github@muglug.com"
}
],
"require": {
"php": "^5.6 || ^7.0",
"composer-plugin-api": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.5",
"composer/composer": "^1.3",
"ext-zip": "*"
},
"autoload": {
"psr-4": {
"Muglug\\PackageVersions\\": "src/PackageVersions"
}
},
"autoload-dev": {
"psr-4": {
"Muglug\\PackageVersionsTest\\": "test/PackageVersionsTest"
}
},
"extra": {
"class": "Muglug\\PackageVersions\\Installer",
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"scripts": {
"post-update-cmd": "Muglug\\PackageVersions\\Installer::dumpVersionsClass",
"post-install-cmd": "Muglug\\PackageVersions\\Installer::dumpVersionsClass"
}
}
PK h^GMµ{üÈu u README.mdnu W+A„¶ PK h^GMmN`S^ ^ ® CONTRIBUTING.mdnu W+A„¶ PK h^GM³¾Ì^Ý
Ý
( K src/PackageVersions/FallbackVersions.phpnu W+A„¶ PK h^GM™ØPi³ ³ ! € src/PackageVersions/Installer.phpnu W+A„¶ PK h^GMfnæx£ £ „1 src/PackageVersions/Versions.phpnu W+A„¶ PK h^GMm
Ñyé é wC CHANGELOG.mdnu W+A„¶ PK h^GMôô‚! ! œ[ LICENSEnu W+A„¶ PK h^GMFoã £
ô_ composer.jsonnu W+A„¶ PK ¡ Ôe