shadiakiki1986/composer-wrapper

There is no license information available for the latest version (0.0.3) of this package.

0.0.3 2017-01-04 15:15 UTC

This package is auto-updated.

Last update: 2024-10-27 03:00:00 UTC


README

Use composer as a library in your php project

This is different than [eviweb/composer-wrapper](composer require eviweb/composer-wrappe://github.com/eviweb/composer-wrapper)

I should probably choose a different name, but I'm too lazy now

Answers SO Run composer with a PHP script in browser

Installation

composer require shadiakiki1986/composer-wrapper

Usage

Example 1

Get the output of composer show --direct as an array in php:

require_once 'vendor/autoload.php';

$cw = new \shadiakiki1986\ComposerWrapper();
$packages = $cw->showDirect();

This will give an associative array with package names as keys and versions as values, e.g. ['composer/composer'=>'1.3.0.0']

Example 2

As above, but with specifying a different project composer.json:

require_once 'vendor/autoload.php';

// note that the below createComposer function supports passing in a ''localConfig'' parameter, as well as ''cwd'' parameter
// Check https://github.com/composer/composer/blob/master/src/Composer/Factory.php#L263
$io = new \Composer\IO\NullIO();
$factory = new \Composer\Factory();
$composer = $factory->createComposer($io,'/path/to/another/composer.json');

$cw = new \shadiakiki1986\ComposerWrapper($composer);
$packages = $cw->showDirect();