PK *]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 *]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 *]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 *]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 *]GM´±à src/PackageVersions/Versions.phpnu W+A„¶ `.
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 *]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 *]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 *]GMµ{üÈu u README.mdnu W+A„¶ PK *]GMmN`S^ ^ ® CONTRIBUTING.mdnu W+A„¶ PK *]GM³¾Ì^Ý
Ý
( K src/PackageVersions/FallbackVersions.phpnu W+A„¶ PK *]GM™ØPi³ ³ ! € src/PackageVersions/Installer.phpnu W+A„¶ PK *]GM´±à „1 src/PackageVersions/Versions.phpnu W+A„¶ PK *]GMm
Ñyé é ï6 CHANGELOG.mdnu W+A„¶ PK *]GMôô‚! ! O LICENSEnu W+A„¶ PK *]GMFoã £
lS composer.jsonnu W+A„¶ PK ¡ LY