yannoff / phpcc

PHP Code compiler - Phar executable compiling utility

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yannoff/phpcc

PHP Code compiler - Phar executable compiling utility

Help Contents

Usage

Synopsis

phpcc --help
phpcc --version
phpcc \
    -e <main> \
    -o <output> \
    [-d <dir> [-d <dir> ...]] \
    [-f <file> [-f <file> ...]] \
    [-b <banner>] \
    [-m <metadata> [-m <metadata> ...]]

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

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
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
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
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
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
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

đź’ˇ ${BINDIR} may be /usr/bin, /usr/local/bin or $HOME/bin

curl -Lo ${BINDIR}/phpcc https://github.com/yannoff/phpcc/releases/latest/download/phpcc

Add execution permissions to the binary

chmod +x ${BINDIR}/phpcc

License

Licensed under the MIT License.

About

PHP Code compiler - Phar executable compiling utility

License:MIT License


Languages

Language:PHP 94.9%Language:Shell 5.1%