Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mpyw/comphar
Pack all composer dependencies into a single phar file.
https://github.com/mpyw/comphar
composer packaging phar php
Last synced: 9 days ago
JSON representation
Pack all composer dependencies into a single phar file.
- Host: GitHub
- URL: https://github.com/mpyw/comphar
- Owner: mpyw
- License: mit
- Created: 2015-08-24T01:47:20.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-05-09T04:30:05.000Z (over 2 years ago)
- Last Synced: 2024-10-13T13:07:47.808Z (23 days ago)
- Topics: composer, packaging, phar, php
- Language: PHP
- Homepage:
- Size: 15.6 KB
- Stars: 73
- Watchers: 5
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Comphar
*Composer + Phar*
Pack all composer dependencies into a single phar file.
## Installation
### 1. Execute composer global installation
Install via [Packagist](https://packagist.org/packages/mpyw/comphar).
```ShellSession
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 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXWriting lock file
Generating autoload files
example@localhost:~$
```### 2. Update `$PATH`
If not yet, you must add **`~/.composer/vendor/bin`** to `$PATH`.
Append the following statement to `~/.bashrc`, `~/.zshrc` and so on.```shell
export PATH="~/.composer/vendor/bin:$PATH"
```## Usage
```ShellSession
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
### 1. Prepare your repository
Prepare `composer.json`.
```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`
Let's generate `vendor.phar` in that directory.
```ShellSession
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
**Even if you have no dependencies**, you have to call `composer install` or `composer update` to adjust your own library to autoloading.
### 3. Enjoy
You can require `vendor.phar` as well as usual `vendor/autoload.php`.
#### Simplest usage
```php
addPsr4('mpyw\\MyOtherPackage\\', '~/my-other-package/src');
$foo = new Foo();
$bar = new Bar();
```### Error: Permission denied
It's possible you run into the error "Permission denied":
```ShellSession
example@localhost:~/my-new-package$ comphar -v
Error: Permission denied: Disable "phar.readonly" and "phar.require_hash"
```In this case, you need to adjust your configuration at the "php.ini":
```
[Phar]
; http://php.net/phar.readonly
phar.readonly = Off; http://php.net/phar.require-hash
phar.require_hash = Off
```