Make .phar packages from information defined in the composer.json file
Go to file
2018-04-06 01:35:44 +02:00
bin Bugfixed autoload.php stuff 2018-04-06 01:35:44 +02:00
src Misc fixes 2018-04-06 01:31:22 +02:00
.gitignore Misc fixes 2018-04-06 01:31:22 +02:00
composer.json Updated composer.json 2018-04-06 01:27:10 +02:00
README.md Initial commit 2018-04-06 01:22:42 +02:00

PharLite: Easy PHAR generator

Make sure PHP can write PHARs in your php.ini before trying anything else.

composer.json options

{
    ...
    "extra": {
        "phar": {
            "include": [ ... ],
            "exclude": [ ... ],
            "index": "web/index.php",
            "output": "pharname.phar",
            "strip": "none",
            "metadata": { ... },
            "preload": [ ... ],
        }
    }
}

include and exclude

Specify additional files or paths to include or exclude.

index: Create a web phar

Specifying this option will automatically opt to create a web phar. The value should point to a valid index file or router.

output: Output filename

Defines the output filename. Defaults to output.phar

strip: Trim file sizes

Valid values are none, all or an array of patterns to match.

"strip": "all"              Strip all files
"strip": "none"             Include everything as is (default)
"strip": [ "src/*.php" ]    All *.php in src/ and subdirectories

Stripping will remove comments and whitepace in files, which makes them smaller but can confuse code that dynamically parses f.ex. docblock comments for routing info etc.

metadata: Phar metadata

Define additional metadata to write to the phar. The following keys are automatically written:

Key Type Description
phar.generator string The string PharLite/x.y (PHP/x.y)
phar.type string One of app, library or web
package.name string The composer package name
package.version string The composer package version

preload: Files to preload

If defined, this should be an array of files to include after composer.json in the stub.

Building

To build a phar from a composer project, just run pharlite. It will build one of the following:

  • Library phar - A single file containing a composer library, complete with autoloaders and all that magic.
  • Application phar - An executable file containing an application and its dependencies.
  • Web phar - A complete website in a single file

If more than one bin is defined in the composer.json, the first one will be the default one, but all defined bins will be available by symlinking the phar to the respective names.

"bin": [ "bin/foo", "bin/bar" ]

output.phar, foo.phar, foo, hello.phar -> calls bin/foo
bar.phar, bar -> calls bin/bar