GithubHelp home page GithubHelp logo

yannoff / phpcc Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 42 KB

PHP Code compiler - Phar executable compiling utility

License: MIT License

PHP 94.88% Shell 5.12%
phar php-archive php-compiler self-executable

phpcc's Introduction

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.

phpcc's People

Contributors

yannoff avatar

Watchers

 avatar

phpcc's Issues

PHP Attributes removed from minified source files

Problem

Given the following attribute.php file:

<?php
// attribute.php

#[\ReturnTypeWillChange]
function hello(): string
{
    echo "Hello World";
} 

Compiling:

phpcc --main attribute.php -o o.phar

Resulting attribute.php file inside the compiled o.phar :

Expected:

<?php #[\ReturnTypeWillChange] function hello(): string { echo "Hello World"; }

Actual:

<?php
function hello(): string { echo "Hello World"; } 

Explanation

This is due to a lack of support for PHP Attributes in the php built-in php_strip_whitespace method.

Solution

Re-impelemnt the whole php source minifying routine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.