Skip to content
This repository was archived by the owner on Sep 6, 2020. It is now read-only.
kherge edited this page Jul 6, 2012 · 16 revisions

To configure Box for your PHP ARchive (PHAR), you will need to create a box.json file.

box.json

This is an example box.json file that uses all of the available settings.

{
    "algorithm": 2,
    "alias": "example.phar",
    "base-path": "/path/to/app",
    "directories": [
        "dir/one",
        "dir/two"
    ],
    "files": [
        "file/one.php",
        "file/two.php"
    ],
    "finder": [
        {
            "name": "*.php",
            "in": "lib/one"
        },
        {
            "name": "*.php",
            "exclude": "Tests",
            "in": "lib/one"
        }
    ],
    "git-version": "package_version",
    "main": "bin/main.php",
    "output": "example.phar",
    "replacements": {
        "tag1": "Value 1",
        "tag2": "Value 2"
    },
    "stub": "src/stub.php"
}

algorithm

The algorithm option is used to set what signature algorithm you want to use. By default, this option is set to Phar::SHA1. You may find other available algorithms at the Phar constants page. The decimal value of the constant is expected in the configuration file. You can use the following table as a guide:

  • Phar::MD5: 1
  • Phar::SHA1: 2
  • Phar::SHA256: 3
  • Phar::SHA512: 4
  • Phar::OPENSSL: 5

A request has been opened for a better way of setting algorithms.

A request has been opened to support using OpenSSL for signing.

alias

The alias is the name of the stream used for loading files from within the PHAR. The name of the alias is registered using the Phar::mapPhar() method when used with the Box generated stub. The default alias is default.phar.

#!/usr/bin/env php
<?php

    Phar::mapPhar('default.phar');

    __HALT_COMPILER();

base-path

The value of base-path is used to find all of the files referred to by the files and directories settings. It is also used to generate the relative paths for the files that have been found, including those found by the finder setting. By default, the directory path to the configuration file is used.

directories

The directories setting is used to recursively find all files that are in the directory that end with .php. These files will then be added to the PHAR, maintaining their relative directory structure. Multiple paths can be provided as an array, or just one as a string.

Note that any files in version control folders, such as .git, will be skipped.

Example directory:

/path/to/dir/
    .git/
        test.php
    sub1/
        file1.php
        file2.php
        file3.php3
        file4.php4
    sub2/
        file1.jpg
        file2.php
        file3.phtml
        file4.php5

Only these files are added to the PHAR:

dir/
    sub1/
        file1.php
        file2.php
    sub2/
        file2.php

files

finder

git-version

main

output

replacements

stub

Clone this wiki locally