PHPackages                             manychois/composery - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. manychois/composery

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

manychois/composery
===================

A strongly-typed PHP library providing a low-level API equivalent to the Composer CLI

v0.0.1(2mo ago)04[4 PRs](https://github.com/manychois/composery/pulls)MITPHPPHP &gt;=8.5CI passing

Since Apr 7Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/manychois/composery)[ Packagist](https://packagist.org/packages/manychois/composery)[ RSS](/packages/manychois-composery/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (7)Versions (14)Used By (0)

Composery
=========

[](#composery)

A strongly-typed PHP library providing a low-level API equivalent to the Composer CLI.

Each Composer command maps to a corresponding method on the `Composer` class. All methods come in two variants: **blocking** (returns a `ComposerResult`) and **streaming** (returns a `Generator` that yields `OutputLine` objects as they arrive).

Requirements
------------

[](#requirements)

- PHP 8.5 or later
- Composer binary accessible on the system (or bundled — see below)

Installation
------------

[](#installation)

```
composer require manychois/composery
```

Bundled Composer binary
-----------------------

[](#bundled-composer-binary)

The test suite ships with a bundled Composer binary at `tests/Integration/composer` (version **2.9.5**, SHA-256 `c86ce603fe836bf0861a38c93ac566c8f1e69ac44b2445d9b7a6a17ea2e9972a`). This binary is used exclusively during integration tests and is not installed as a production dependency.

Quick start
-----------

[](#quick-start)

```
use Manychois\Composery\Composer;
use Manychois\Composery\Environment;

$env = new Environment(workingDir: '/path/to/your/project');
$composer = new Composer($env);

// Blocking — waits until the command finishes
$result = $composer->install();

if ($result->successful()) {
    echo "Installed in {$result->duration()}s\n";
} else {
    echo "Failed (exit {$result->exitCode()}):\n{$result->output()}";
}
```

Streaming output in real time
-----------------------------

[](#streaming-output-in-real-time)

```
use Manychois\Composery\Composer;
use Manychois\Composery\Command\UpdateOptions;
use Manychois\Composery\Environment;
use Manychois\Composery\Runner\OutputSource;

$env = new Environment(workingDir: '/path/to/your/project');
$composer = new Composer($env);

$options = new UpdateOptions();
$options->noDev = true;

$gen = $composer->updateStreaming(options: $options);

foreach ($gen as $line) {
    $prefix = $line->source === OutputSource::Stderr ? '[err] ' : '';
    echo $prefix . $line->content . "\n";
}

$result = $gen->getReturn();
echo "Exit code: {$result->exitCode()}\n";
```

Environment configuration
-------------------------

[](#environment-configuration)

`Environment` controls the working directory, `COMPOSER_HOME`, the PHP memory limit, and an optional explicit path to the Composer binary.

```
use Manychois\Composery\Environment;

$env = new Environment(
    workingDir:   '/var/www/app',
    composerHome: '/tmp/composer-home',   // default
    memoryLimit:  '1G',                   // default: 512M
    binaryPath:   '/usr/local/bin/composer', // null = auto-detect
);
```

### Binary resolution order

[](#binary-resolution-order)

When `binaryPath` is `null`, `BinaryLocator` searches in this order:

1. `binaryPath` from `Environment` (if set)
2. `$COMPOSER_HOME/composer` or `$COMPOSER_HOME/composer.phar`
3. `which composer` (Unix) / `where composer` (Windows)
4. `composer.phar` in `workingDir`

Throws `ComposerNotFoundException` if nothing is found.

Global options
--------------

[](#global-options)

Every options class extends `AbstractGlobalOption`, which exposes the following flags available to all commands:

PropertyCLI flagDefault`$help``--help` / `-h``false``$noCache``--no-cache``false``$noPlugins``--no-plugins``false``$noScripts``--no-scripts``false``$profile``--profile``false``$quiet``--quiet` / `-q``false``$verbose``--verbose` / `-v``false``$version``--version` / `-V``false``$workingDir``--working-dir=` / `-d``null``--no-interaction` and `--no-ansi` are always injected by the runner and are **not** exposed as options.

API reference
-------------

[](#api-reference)

`Composer` is constructed with an `Environment` and an optional `BinaryLocator`:

```
new Composer(Environment $environment, ?BinaryLocator $locator = null)
```

Every command is available in a blocking variant that returns `ComposerResult` and a streaming variant that returns a `Generator`. Options classes carry the same name as the method with an `Options` suffix (e.g. `install` → `InstallOptions`). All options classes extend `AbstractGlobalOption`; see the [global options](#global-options) table above for the inherited flags.

Blocking methodStreaming methodComposer docs`init``initStreaming`[init](https://getcomposer.org/doc/03-cli.md#init)`install``installStreaming`[install](https://getcomposer.org/doc/03-cli.md#install-i)`update``updateStreaming`[update](https://getcomposer.org/doc/03-cli.md#update-u-upgrade)`require``requireStreaming`[require](https://getcomposer.org/doc/03-cli.md#require-r)`remove``removeStreaming`[remove](https://getcomposer.org/doc/03-cli.md#remove-rm-uninstall)`dumpAutoload``dumpAutoloadStreaming`[dump-autoload](https://getcomposer.org/doc/03-cli.md#dump-autoload-dumpautoload)`validate``validateStreaming`[validate](https://getcomposer.org/doc/03-cli.md#validate)`show``showStreaming`[show](https://getcomposer.org/doc/03-cli.md#show-info)`outdated``outdatedStreaming`[outdated](https://getcomposer.org/doc/03-cli.md#outdated)`checkPlatformReqs``checkPlatformReqsStreaming`[check-platform-reqs](https://getcomposer.org/doc/03-cli.md#check-platform-reqs)`composer.json` as a typed model (`Schema\Project`)
---------------------------------------------------

[](#composerjson-as-a-typed-model-schemaproject)

The `Manychois\Composery\Schema` namespace provides value objects that mirror the [`composer.json` schema](https://getcomposer.org/doc/04-schema.md). The root type is `Project`: a mutable, strongly-typed representation of a manifest after you decode the file to a PHP array.

```
use Manychois\Composery\Schema\Project;

$path = '/path/to/your/project/composer.json';
$json = \json_decode((string) \file_get_contents($path), true);
\assert(\is_array($json));

$project = Project::parse($json);

echo $project->name ?? '(unnamed)';
print_r($project->require);
```

`Project::parse()` walks the associative array and fills public properties. Known nested structures become dedicated classes (for example `Author`, `Support`, `Autoload`, `AutoloadDev`, `Scripts`, `ProjectConfig`, `Archive`, `PhpExt`, `Source`, `Dist`, and `Funding`). String-key dependency maps (`require`, `require-dev`, `replace`, `conflict`, `provide`, `suggest`) stay as `array`. `minimum-stability` is parsed into the `MinimumStability` enum when present. The `repositories` field is a `list` because entries can be objects or shorthand strings.

`Project` implements `JsonSerializable`. Calling `json_encode($project)` emits a shape suitable for persisting back to JSON (only non-empty / non-null fields are included, matching typical `composer.json` usage).

This layer is separate from the `Composer` runner: it does not invoke Composer or read files by itself. Use it whenever your application needs to inspect or build manifest data with IDE and PHPStan-friendly types instead of raw arrays.

Return types
------------

[](#return-types)

### `ComposerResult`

[](#composerresult)

MethodReturn typeDescription`successful()``bool``true` when exit code is 0`exitCode()``int`Raw process exit code`output()``string`Combined stdout + stderr output`duration()``float`Wall-clock time in seconds### `OutputLine` (streaming)

[](#outputline-streaming)

PropertyTypeDescription`$content``string`The line text (newline stripped)`$source``OutputSource``OutputSource::Stdout` or `OutputSource::Stderr``$timestamp``float``microtime(true)` when the line was capturedThe generator's return value (available via `$gen->getReturn()` after the loop) is the `ComposerResult` for the completed command.

Enums
-----

[](#enums)

### `PreferMode`

[](#prefermode)

CaseCLI flag`PreferMode::Dist``--prefer-dist``PreferMode::Source``--prefer-source``PreferMode::None`*(no flag emitted)*### `ListFormat`

[](#listformat)

CaseCLI value`ListFormat::Text`*(default, no flag emitted)*`ListFormat::Json``--format=json`Exceptions
----------

[](#exceptions)

ClassThrown when`ComposerNotFoundException`No Composer binary can be located`ComposerRunFailedException`*(reserved for future use)*

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance89

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

87d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3290769?v=4)[Siu Pang Tommy Choi](/maintainers/manychois)[@manychois](https://github.com/manychois)

---

Top Contributors

[![manychois](https://avatars.githubusercontent.com/u/3290769?v=4)](https://github.com/manychois "manychois (15 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

composercomposer-apicomposer-wrapperphp8composer

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/manychois-composery/health.svg)

```
[![Health](https://phpackages.com/badges/manychois-composery/health.svg)](https://phpackages.com/packages/manychois-composery)
```

###  Alternatives

[jean85/pretty-package-versions

A library to get pretty versions strings of installed dependencies

1.3k315.9M84](/packages/jean85-pretty-package-versions)[ergebnis/composer-normalize

Provides a composer plugin for normalizing composer.json.

1.1k41.4M2.8k](/packages/ergebnis-composer-normalize)[icanhazstring/composer-unused

Show unused packages by scanning your code

1.7k7.9M224](/packages/icanhazstring-composer-unused)[bamarni/composer-bin-plugin

No conflicts for your bin dependencies

53024.4M1.1k](/packages/bamarni-composer-bin-plugin)[composer/metadata-minifier

Small utility library that handles metadata minification and expansion.

181123.3M25](/packages/composer-metadata-minifier)[shipmonk/composer-dependency-analyser

Fast detection of composer dependency issues (dead dependencies, shadow dependencies, misplaced dependencies)

6198.4M669](/packages/shipmonk-composer-dependency-analyser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
