An open API service indexing awesome lists of open source software.

https://github.com/yannoff/phpcc

PHP Code compiler - Phar executable compiling utility
https://github.com/yannoff/phpcc

phar php-archive php-compiler self-executable

Last synced: 4 months ago
JSON representation

PHP Code compiler - Phar executable compiling utility

Awesome Lists containing this project

README

          

# yannoff/phpcc

PHP Code compiler - Phar executable compiling utility

## Help Contents

- [Usage](#usage)
- [Synopsis](#synopsis)
- [Options/Arguments](#optionsarguments)
- [Examples](#examples)
- [A concrete use-case: the `phpcc` self-compiling command](#a-concrete-use-case-the-phpcc-self-compiling-command)
- [Example 1: PHP sources located in several directories](#example-1-php-sources-located-in-several-directories)
- [Example 2: Multiple extensions in the same directory](#example-2-multiple-extensions-in-the-same-directory)
- [Example 3: Standalone php script](#example-3-standalone-php-script)
- [Example 4: Add sparse single PHP files](#example-4-add-sparse-single-php-files)
- [Example 5: Adding metadata to the archive](#example-5-adding-metadata-to-the-archive)
- [Install](#install)
- [Requirements](#requirements)
- [Quick install](#quick-install)
- [License](#license)

## Usage

### Synopsis

```
phpcc --help
phpcc --version
```

```
phpcc \
-e \
-o \
[-d [-d ...]] \
[-f [-f ...]] \
[-b ] \
[-m [-m ...]]
```

### Options/Arguments

> The output and entrypoint scripts are mandatory.

Name / Shorthand | Type | Description |Required
--------------------|:-----:|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------:
`--output`, `-o` | value | The Phar archive output file |y
`--main`, `-e` | value | The main application entrypoint script |y
`--banner`, `-b` | value | Specify the filepath to the legal notice banner
_Will be included in the human-readable part of the stub._ |n
`--file`, `-f` | multi | Adds a single file to the archive |n
`--dir`, `-d` | multi | Adds a sources directory to the archive
_Possible dir spec formats:
- `$dir` => include all files in directory
- `$dir:$extension` => filter files on a specific extension_ |n
`--meta`, `-m` | multi | Adds a metadata to the archive
_Metadata must be specified in the `$key:$value` format_ |n
`--shebang-less` | flag | Produce a stub deprived of the shebang directive
_Useful when the phar is meant to be included instead of being executed directly_ |n
`--quiet`, `-q` | flag | Reduce output messages amount: set verbosity level to `INFO` instead of default `DEBUG` |n

### Examples

#### A concrete use-case: the `phpcc` self-compiling command

```bash
phpcc -d src:php -d vendor:php -e bin/compile.php -o bin/phpcc -b .banner
```

#### Example 1: PHP sources located in several directories

- Add all `*.php` files from `src/` and `vendor/` dirs
- Define `main.php` as the stub main entrypoint script
- Save compiled phar executable to `bin/foobar`

```bash
phpcc -d src:php -d vendor:php -e main.php -o bin/foobar
```
#### Example 2: Multiple extensions in the same directory

- Add all `*.php` and `*.phtml` files from `src/` dir
- Define `main.php` as the stub main entrypoint script
- Save compiled phar executable to `bin/foobar`

```bash
phpcc -d src:php -d src:phtml -e main.php -o bin/foobar
```

#### Example 3: Standalone php script

- Define `app.php` as the stub main entrypoint script
- Save compiled phar executable to `foobar.phar`
- Use `LICENSE` file contents as legal notice banner

```bash
phpcc -e app.php -o foobar.phar -b LICENSE
```

#### Example 4: Add sparse single PHP files

- Define `app.php` as the stub main entrypoint script
- Save compiled phar executable to `foobar.phar`
- Add `foo.php` and `bar.php` files to the archive

```bash
phpcc -e app.php -o foobar.phar -f foo.php -f bar.php
```

#### Example 5: Adding metadata to the archive

- Define `app.php` as the stub main entrypoint script
- Save compiled phar executable to `bin/acme`
- Add the `license` & `author` metadata to the archive

```bash
phpcc -e app.php -o bin/acme -m license:MIT -m author:yannoff
```

## Install

### Requirements

- `php` or `paw` 7.1+
- `phar.readonly` php config directive must be set to `Off`

### Quick install

_Get the latest release from Github_

> :bulb: `${BINDIR}` may be /usr/bin, /usr/local/bin or $HOME/bin

```bash
curl -Lo ${BINDIR}/phpcc https://github.com/yannoff/phpcc/releases/latest/download/phpcc
```
_Add execution permissions to the binary_

```bash
chmod +x ${BINDIR}/phpcc
```

## License

Licensed under the [MIT License](LICENSE).