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

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

nanbando/embedded-composer
==========================

Embed Composer into another application

1.0.0(5y ago)04MITPHPPHP ^7.4 || ^8.0.1

Since Jun 23Pushed 5y agoCompare

[ Source](https://github.com/nanbando/dflydev-embedded-composer)[ Packagist](https://packagist.org/packages/nanbando/embedded-composer)[ RSS](/packages/nanbando-embedded-composer/feed)WikiDiscussions master Synced 3w ago

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

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

[](#embedded-composer)

Embed [Composer](http://getcomposer.org) into another application.

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

[](#installation)

Through [Composer](http://getcomposer.org) as [dflydev/embedded-composer](https://packagist.org/packages/dflydev/embedded-composer).

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.

```
