PHPackages                             yosymfony/embedded-composer - 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. yosymfony/embedded-composer

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

yosymfony/embedded-composer
===========================

Embed Composer into another application

v1.0.0(9y ago)233.8k↓30%2MITPHPPHP &gt;=5.5

Since Jan 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/yosymfony/Embedded-composer)[ Packagist](https://packagist.org/packages/yosymfony/embedded-composer)[ RSS](/packages/yosymfony-embedded-composer/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (2)Used By (2)

Embedded Composer
=================

[](#embedded-composer)

[![Build Status](https://camo.githubusercontent.com/fbde6695cb66fc1bb2c60bf6404c0e437e3d257e6baa1f2668d8e1e7b4d03bda/68747470733a2f2f7472617669732d63692e6f72672f796f73796d666f6e792f456d6265646465642d636f6d706f7365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yosymfony/Embedded-composer)

Embed [Composer](https://getcomposer.org/) into another application. This library is based on [dflydev-embedded-composer](https://github.com/dflydev/dflydev-embedded-composer). Due to this latter seems abandoned, I decided to fork this one and start my own way.

Why Would I Want To Embed Composer?
-----------------------------------

[](#why-would-i-want-to-embed-composer)

Imagine a console application shipped as a phar. If it is desired for the application to be extensible based on which directory it is in (say one set of plugins should be used in one directory but an entirely different set of plugins used in another directory) one cannot simply define a `composer.json`in both directories and run `composer install`.

Why not? Because the application shipped with a specific set of dependencies. Composer cannot add more dependencies without running the risk of introducing conflicts. The answer is to embed Composer into the application so that Composer can merge the dependencies already installed for the application with the dependencies defined in a specific directory's `composer.json`.

The end result is a set of dependencies that satisfy the directory specific requirements while taking into account the dependencies *already installed*for the console application.

While this is required for a phar distributed application this technique can be applied to any globally installed application that needs to be runtime extensible.

Usage
-----

[](#usage)

### Basics

[](#basics)

The following is an example `bin/myapp` style script that can be used either installed via Composer (`vendor/bin/myapp`) or installed globally (`/usr/local/bin/myapp`).

#### myapp.php (bin)

[](#myappphp-bin)

A shared block of code to initialize Embedded Composer from an application.

```
// assume $classLoader is somehow defined prior to this block of
// code and contains the Composer class loader from the command
//
// see next two blocks of code

use Yosymfony\EmbeddedComposer\EmbeddedComposerBuilder;

$input = new ArgvInput;

$projectDir = '/my-project-dir'

$embeddedComposerBuilder = new EmbeddedComposerBuilder(
    $classLoader,
    $projectDir
);

$embeddedComposer = $embeddedComposerBuilder
    ->setComposerFilename('composer.json')
    ->setVendorDirectory('.vendor')
    ->build();

$embeddedComposer->processAdditionalAutoloads();

// application is now ready to be run taking both the embedded
// dependencies and directory specific dependencies into account.
```

#### myapp (bin)

[](#myapp-bin)

Example bin script (`bin/myapp`) that requires the shared block of code after it locates the correct autoloader.

```
#!/usr/bin/env php
