PHPackages                             mpyw/comphar - 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. mpyw/comphar

ActiveProject

mpyw/comphar
============

Pack all composer dependencies into a single phar file

v1.0.1(7y ago)731.6k5[1 issues](https://github.com/mpyw/comphar/issues)MITPHPPHP &gt;=5.4.0

Since Aug 30Pushed 3y ago3 watchersCompare

[ Source](https://github.com/mpyw/comphar)[ Packagist](https://packagist.org/packages/mpyw/comphar)[ RSS](/packages/mpyw-comphar/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (3)Used By (0)

Comphar
=======

[](#comphar)

*Composer + Phar*

Pack all composer dependencies into a single phar file.

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

[](#installation)

### 1. Execute composer global installation

[](#1-execute-composer-global-installation)

Install via [Packagist](https://packagist.org/packages/mpyw/comphar).

```
example@localhost:~$ composer global require mpyw/comphar:^1.0
Changed current directory to /Users/mpyw/.composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing mpyw/comphar (dev-master XXXXXXX)
    Cloning XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Writing lock file
Generating autoload files
example@localhost:~$
```

### 2. Update `$PATH`

[](#2-update-path)

If not yet, you must add **`~/.composer/vendor/bin`** to `$PATH`.
Append the following statement to `~/.bashrc`, `~/.zshrc` and so on.

```
export PATH="~/.composer/vendor/bin:$PATH"
```

Usage
-----

[](#usage)

```
example@localhost:~$ comphar -h
Usage: ./comphar [options]
Options:
  -h, --help             Show help.
  -v, --verbose          Verbose output.
  -o, --out       Output archive name. Default to "vendor.phar".
  -d, --dir       Project root directory. Default to getcwd().
      --yes              Without confirmation.
example@localhost:~$
```

Example
-------

[](#example)

### 1. Prepare your repository

[](#1-prepare-your-repository)

Prepare `composer.json`.

```
{
    "name": "mpyw/my-new-package",
    "description": "This is a stupid example",
    "require": {
        "mpyw/my-dependency-1": "@dev",
        "mpyw/my-dependency-2": "1.0.0",
    },
    "autoload": {
        "psr-4": {
            "mpyw\\MyNewPackage\\": "src/"
        }
    }
}
```

### 2. Generate `vendor.phar`

[](#2-generate-vendorphar)

Let's generate `vendor.phar` in that directory.

```
example@localhost:~/my-new-package$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
example@localhost:~/my-new-package$ comphar -v
Project directory: ~/my-new-package
Output filename: ~/my-new-package/vendor.phar
Continue? [y/n]: y
Added: ...
Added: ...
Added: ...
Added: ...
Added: ...
example@localhost:~/my-new-package$
```

#### Note

[](#note)

**Even if you have no dependencies**, you have to call `composer install` or `composer update` to adjust your own library to autoloading.

### 3. Enjoy

[](#3-enjoy)

You can require `vendor.phar` as well as usual `vendor/autoload.php`.

#### Simplest usage

[](#simplest-usage)

```
