Following issue https://github.com/phar-io/version/issues/28 that is now fixed, I may propose a solution to parse any composer.lock
file to generate a Manifest.
Goal Write a manifest from any Github repositories, quickly without xml structure errors with the real components installed !
To avoid rewrites too much code, I've reused lot of existing architecture as much as possible.
That means:
<?php
use PharIo\Manifest\ManifestLoader;
use PharIo\Manifest\ManifestSerializer;
$manifest = ManifestLoader::fromComposer("/path/to/composer.lock");
echo (new ManifestSerializer)->serializeToString($manifest);
New exception PharIo\Manifest\NotEncodableValueException
is raised if composer.lock
could not be decoded.
All new elements are in new directory src/json
to separate from other existing elements.
Add a new example to demonstrate feature with a PHPUnit 5.6.5 composer.lock
(generated today, with existing dependencies versions)
As composer.lock
does not contains all necessary informations required to generate a fully real manifest, some entry are built with defaults:
contains
tag
copyright
tag
Here is an example to build the manifest of PHPUnit 5.6.5 (compares with https://github.com/phar-io/manifest/blob/master/tests/_fixture/phpunit-5.6.5.xml)
<?php
// script examples/example-02.php
use PharIo\Manifest\ManifestLoader;
use PharIo\Manifest\ManifestSerializer;
require __DIR__ . '/../vendor/autoload.php';
$manifest = ManifestLoader::fromComposer(
dirname(__DIR__) . '/tests/_fixture/phpunit-5.6.5_composer.lock'
);
echo (new ManifestSerializer)->serializeToString($manifest);
That prints following manifest
<?xml version="1.0" encoding="UTF-8"?>
<phar xmlns="https://phar.io/xml/manifest/1.0">
<contains name="vendor/package" version="0.0.0-dev" type="library"/>
<copyright>
<author name="John Doe" email="[email protected]"/>
<license type="MIT" url="https://spdx.org/licenses/MIT.html"/>
</copyright>
<requires>
<php version="^5.6 || ^7.0">
<ext name="dom"/>
<ext name="json"/>
<ext name="mbstring"/>
<ext name="xml"/>
<ext name="libxml"/>
</php>
</requires>
<bundles>
<component name="doctrine/instantiator" version="1.0.5"/>
<component name="myclabs/deep-copy" version="1.7.0"/>
<component name="phpdocumentor/reflection-common" version="1.0.1"/>
<component name="phpdocumentor/reflection-docblock" version="3.3.2"/>
<component name="phpdocumentor/type-resolver" version="0.4.0"/>
<component name="phpspec/prophecy" version="1.10.3"/>
<component name="phpunit/php-code-coverage" version="4.0.8"/>
<component name="phpunit/php-file-iterator" version="1.4.5"/>
<component name="phpunit/php-text-template" version="1.2.1"/>
<component name="phpunit/php-timer" version="1.0.9"/>
<component name="phpunit/php-token-stream" version="1.4.12"/>
<component name="phpunit/phpunit-mock-objects" version="3.4.4"/>
<component name="sebastian/code-unit-reverse-lookup" version="1.0.2"/>
<component name="sebastian/comparator" version="1.2.4"/>
<component name="sebastian/diff" version="1.4.3"/>
<component name="sebastian/environment" version="2.0.0"/>
<component name="sebastian/exporter" version="2.0.0"/>
<component name="sebastian/global-state" version="1.1.1"/>
<component name="sebastian/object-enumerator" version="2.0.1"/>
<component name="sebastian/recursion-context" version="2.0.0"/>
<component name="sebastian/resource-operations" version="1.0.0"/>
<component name="sebastian/version" version="2.0.1"/>
<component name="symfony/polyfill-ctype" version="1.19.0"/>
<component name="symfony/yaml" version="3.4.47"/>
<component name="webmozart/assert" version="1.9.1"/>
</bundles>
</phar>