An application for building and managing Phars.

Related tags

Miscellaneous box2
Overview

This project has been moved to https://github.com/box-project/box

If you are looking to upgrade, don't forget to have a look at the upgrade guide.


Box

Build Status

What is it?

The Box application simplifies the Phar building process. Out of the box (no pun intended), the application can do many great things:

  • Add, replace, and remove files and stubs in existing Phars.
  • Extract a whole Phar, or cherry pick which files you want.
  • Retrieve information about the Phar extension, or a Phar file.
    • List the contents of a Phar.
  • Verify the signature of an existing Phar.
  • Generate RSA (PKCS#1 encoded) private keys for OpenSSL signing.
    • Extract public keys from existing RSA private keys.
  • Use Git tags and short commit hashes for versioning.

Since the application is based on the Box library, you get its benefits as well:

  • On the fly search and replace of placeholders.
  • Compact file contents based on file type.
  • Generate custom stubs.

Forks

Because of the lack of proper maintenance on my part, I created a wiki page to list the known forks of this project. Please feel free to add to this list. You can find the wiki page here.

How do I get started?

You can use Box in one of three ways:

As a Phar (Recommended)

You may download a ready-to-use version of Box as a Phar:

$ curl -LSs https://box-project.github.io/box2/installer.php | php

The command will check your PHP settings, warn you of any issues, and the download it to the current directory. From there, you may place it anywhere that will make it easier for you to access (such as /usr/local/bin) and chmod it to 755. You can even rename it to just box to avoid having to type the .phar extension every time.

$ box --version

Whenever a new version of the application is released, you can simply run the update command to get the latest version:

$ box update

As a Global Composer Install

This is probably the best way when you have other tools like phpunit and other tools installed in this way:

$ composer global require kherge/box --prefer-source

As a Composer Dependency

You may also install Box as a dependency for your Composer managed project:

$ composer require --dev kherge/box

(or)

{
    "require-dev": {
        "kherge/box": "~2.5"
    }
}

Be aware that using this approach requires additional configuration steps to prevent Box's own dependencies from accidentally being added to your Phar, causing file size bloat. You can find more information about this issue on the wiki.

Once you have installed the application, you can run the help command to get detailed information about all of the available commands. This should be your go-to place for information about how to use Box. You may also find additional useful information on the wiki. If you happen to come across any information that could prove to be useful to others, the wiki is open for you to contribute.

$ box help

Creating a Phar

To get started, you may want to check out the example application that is ready to be built by Box. How your project is structured is entirely up to you. All that Box requires is that you have a file called box.json at the root of your project directory. You can find a complete and detailed list of configuration settings available by seeing the help information for the build command:

$ box help build

You may find example configuration files for popular projects on the wiki.

Once you have configured your project using box.json (or box.json.dist), you can simply run the build command in the directory containing box.json:

$ box build -v

The -v option enabled verbose output. This will provide you with a lot of useful information for debugging your build process. Once you are satisfied with the results, I recommend not using the verbose option. It may considerably slow down the build process.

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

GPG Signature

You can find kherge's GPG on keybase.io.

32E4 B747 57B1 D652 34FC 389F 293D 7712 4151 5FE8
Comments
  • Building fatals when building a larger project

    Building fatals when building a larger project

    When I try to build a phar for phpDocumentor I get the following error:

    ? Generating new stub...
    ? Compressing...
    PHP Fatal error:  Uncaught exception 'ErrorException' with message 'proc_open(): unable to create pipe Too many open files' in phar:///home/mvriel/Copy/Projects/OSS/phpDocumentor/phpDocumentor2/box.phar/src/vendors/symfony/console/Symfony/Component/Console/Application.php:974
    Stack trace:
    #0 [internal function]: KevinGH\Box\Application->KevinGH\Box\{closure}(2, 'proc_open(): un...', 'phar:///home/mv...', 974, Array)
    #1 phar:///home/mvriel/Copy/Projects/OSS/phpDocumentor/phpDocumentor2/box.phar/src/vendors/symfony/console/Symfony/Component/Console/Application.php(974): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
    #2 phar:///home/mvriel/Copy/Projects/OSS/phpDocumentor/phpDocumentor2/box.phar/src/vendors/symfony/console/Symfony/Component/Console/Application.php(793): Symfony\Component\Console\Application->getSttyColumns()
    #3 phar:///home/mvriel/Copy/Projects/OSS/phpDocumentor/phpDocumentor2/box.phar/src/vendors/symfony/console/Symfony/Component/Console/Application.php(754): Symfony\Component\Console\Application in phar:///home/mvriel/Copy/Projects/OSS/phpDocumentor/phpDocumentor2/box.phar/src/vendors/symfony/console/Symfony/Component/Console/Application.php on line 974
    
    Bug 
    opened by mvriel 26
  • Consider Added support to map file

    Consider Added support to map file

    Hello. I'm trying your library. It seems cool, thanks. But I have an issue.

    I use composer, with the native autoloader, but I use a mount point like that This is not my project, this is just a sample.

    My issue is that the autoloader can find class a the root of my project. But If I hack and copy the lib to the target-dir, it works.

    So it could me very nice to add a new option: a map between real path, and phar path:

    "map": {
      "src": "SensioLabs/Bundle/ConnectBundle"
    }
    
    Enhancement 
    opened by lyrixx 16
  • Error including

    Error including "index.php" even when "web" is set to false.

    I'm on the latest build of Box 2.0. I tried basically started with the box.json.dist file that ships with Box when making my own box file, which looks like this:

    {
        "alias": "craft.phar",
        "chmod": "0755",
        "directories": ["src/lib"],
        "finder": [
            {
                "name": "*.php",
                "exclude": [
                    "phpunit",
                    "phpunit-test-case",
                    "Tester",
                    "Tests",
                    "tests",
                    "yaml"
                ],
                "in": "src/vendors"
            }
        ],
        "main": "bin/craft",
        "output": "craft.phar",
        "stub": true
    }
    

    However, I am getting an error that the index.php doesn't exist when actually trying to run the generated Phar. So, I cloned down Box itself and ran box build and get the same error on a clean clone of Box:

    Warning: include(phar:///media/sf_Code/Laboratory/Box/box-2.0.0-rc.1-8-g77f3c19.phar/index.php):
    
    opened by taylorotwell 14
  • Phar file for v2.7.4 is broken [unexpected T_STRING in Process.php]

    Phar file for v2.7.4 is broken [unexpected T_STRING in Process.php]

    Box project claims to work under PHP 5.3.3

    This is not true anymore for v2.7.4 phar file, v2.7.2 phar file is working. Failing example: https://travis-ci.org/FriendsOfPHP/PHP-CS-Fixer/jobs/152603392#L963

    The reason is the way that box phar file was built - it uses too new deps, exactly Symfony v3.x components (in general it allows v2 || v3), which won't run under PHP 5.3.3. I would say that build is done on newer PHP version. It could be avoided by updating component deps before building the box phar with "platform": {"php": "5.3.3"} in composer.json file (example).

    Sadly, I cannot help more as phar file is built outside Travis (probably locally by project maintainers).

    Bug 
    opened by keradus 13
  • Extract class is always included & causes error

    Extract class is always included & causes error

    This is always included even if I do not include extract in my JSON or set it to false:

    if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
    Phar::interceptFileFuncs();
    set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
    Phar::webPhar(null, $web);
    include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
    return;
    }
    

    Also the Extract_Phar::START somehow evaluates to index.php, which is a non-existent file in the .phar. This is my repo (including the box.json): https://github.com/rugk/threema-msgapi-sdk-php/tree/536457329376dc657cb02a558c9dd8d802af2b67

    opened by rugk 11
  • Implement signed package

    Implement signed package

    Hi!

    I've been using box, and recently wrote a blog post for creating signed PHAR files using Box, as well as automating creation and distribution:

    • https://mwop.net/blog/2015-12-14-secure-phar-automation.html

    One point that has been raised by some of my readers is that I detail creating a signed PHAR, but then use an unsigned phar to create it, namely the one from box-project.

    It'd be awesome if you could sign your phar files and provide a public key for verification; essentially, it would be one more level of trust in the chain. Let me know if I can be of any assistance in this!

    Enhancement 
    opened by weierophinney 11
  • Adds release date replacement (closes #103)

    Adds release date replacement (closes #103)

    As mentioned in #103 it would be nice to specify a release date a la composer. The placeholder name is datetime but maybe releasedatecould be more meaningful.

    As of now the output is a string like 2015-10-28 10:34:23

    opened by micheleorselli 11
  • '  failed to open stream: No such file or directory ' with laravel

    ' failed to open stream: No such file or directory ' with laravel

    i want to build application with laravel and after i build it with 'box' the box.json file ::

    {
        "alias": "test.phar",
        "chmod": "0755",
        "directories": ["src/app", "src/public", "src/bootstrap"],
        "files": [
            "src/vendor/autoload.php"
        ],
        "finder": [{
            "name": "*.php",
            "exclude": ["Tests", "tests", "test-suite"],
            "in": "src/vendor"
        }],
    
        "git-version": "package_version",
        "main": "bin/index",
        "output": "bin/blog.phar",
        "stub": true
    }
    

    and run it from the command line the console print this error :

    PHP Warning:  require(/vendor/laravel/framework/src/Illuminate/Foundation/start.php): failed to open stream: No such file or directory in phar:///opt/lampp/htdocs/phars/test/bin/blog.phar/src/bootstrap/start.php on line 60
    PHP Stack trace:
    PHP   1. {main}() /opt/lampp/htdocs/phars/test/bin/blog.phar:0
    PHP   2. require() /opt/lampp/htdocs/phars/test/bin/blog.phar:10
    PHP   3. require() phar:///opt/lampp/htdocs/phars/test/bin/blog.phar/bin/index:3
    PHP   4. require_once() phar:///opt/lampp/htdocs/phars/test/bin/blog.phar/src/public/index.php:35
    PHP Fatal error:  require(): Failed opening required '/vendor/laravel/framework/src/Illuminate/Foundation/start.php' (include_path='phar:///opt/lampp/htdocs/phars/test/bin/blog.phar/src/vendor/phpseclib/phpseclib/phpseclib:.:/opt/lampp/lib/php') in phar:///opt/lampp/htdocs/phars/test/bin/blog.phar/src/bootstrap/start.php on line 60
    PHP Stack trace:
    PHP   1. {main}() /opt/lampp/htdocs/phars/test/bin/blog.phar:0
    PHP   2. require() /opt/lampp/htdocs/phars/test/bin/blog.phar:10
    PHP   3. require() phar:///opt/lampp/htdocs/phars/test/bin/blog.phar/bin/index:3
    PHP   4. require_once() phar:///opt/lampp/htdocs/phars/test/bin/blog.phar/src/public/index.php:35
    

    and my directory structure :

    .
    ├── bin
    │   ├── blog.phar      # the output
    │   ├── index            # the main file
    │   ├── index.php    ## to access the phar from the browser
    │   └── storage
    ├── box.json
    └── src
        ├── app
        ├── artisan
        ├── bootstrap
        │   ├── autoload.php
        │   ├── paths.php
        │   └── start.php
        ├── composer.json
        ├── composer.lock
        ├── CONTRIBUTING.md
        ├── phpunit.xml
        ├── public
        │   ├── favicon.ico
        │   ├── index.php         ## the main file for web app
        │   ├── packages
        │   └── robots.txt
        ├── readme.md
        ├── server.php
        └── vendor
    
    

    where is my mistake ??

    opened by ghost 11
  • Merge box.json and box.json.dist

    Merge box.json and box.json.dist

    Hi! :)

    At the moment, when running box with a box.json and a box.json.dist present, box completely ignores box.json.dist. I think it would be great if box would merge both, because that would allow to define the defaults in the .dist and to override specific local settings (private key) in the box.json without having to copy everything.

    Cheers, Bernhard

    opened by webmozart 7
  • Command: missing bootstrap loading fixed

    Command: missing bootstrap loading fixed

    There is actually silent error ATM when loading bootstrap. This should really load it.

    It's never used, only in tests, see loadBootstrap method presence

    opened by TomasVotruba 7
  • New feature: Support phar update

    New feature: Support phar update

    Hello,

    It could be very nice to be able to trigger: box update. Because when the project is quite big, the phar compilation is slow ;) We already did a things like this, so it's possible...

    Enhancement 
    opened by lyrixx 7
  • Some dependencies are abandoned

    Some dependencies are abandoned

    Some dependencies are abandoned:

    Package phine/exception is abandoned, you should avoid using it. No replacement was suggested.
    Package phine/path is abandoned, you should avoid using it. No replacement was suggested.
    Package herrera-io/version is abandoned, you should avoid using it. No replacement was suggested.
    Package herrera-io/json is abandoned, you should avoid using it. Use kherge/json instead.
    Package herrera-io/phar-update is abandoned, you should avoid using it. No replacement was suggested.
    Package herrera-io/annotations is abandoned, you should avoid using it. No replacement was suggested.
    
    opened by filips123 0
  • Docker image

    Docker image

    I have written a Docker image (from official php7 alpine3 image) to use this amazing tool:

    • https://github.com/ebuildy/docker-box
    • https://hub.docker.com/r/ebuildy/box/

    docker run -v $PWD:/app ebuildy/box:v0.0.4 build

    Tell me what do you think about!

    opened by ebuildy 3
  • Can't build without git

    Can't build without git

    Unfortunately, where I work we still use svn to version control. And I had to make a copy of the project and git init then git commit to being able to build.

    opened by paulovitorbal 3
  • Issue when including Crypt/RSA.php

    Issue when including Crypt/RSA.php

    Fatal error: Class 'phpseclib\Crypt\Common\AsymmetricKey' not found in /var/www/html/kowboykit.com/htdocs/phpseclib/Crypt/RSA.php on line 63

    Is throwing every time I use include('Crypt/RSA.php');

    opened by mtstedman 0
  • Box allows Symfony 3.x console component, but uses 2.x Dialog helper internally

    Box allows Symfony 3.x console component, but uses 2.x Dialog helper internally

    Dialog helper was deprecated from 2.5, should be replaced by Question helper. Breaks on asking for the passphrase to a private key when signing phars with openssl. Temporary workaround, when installing box as an isolated composer dev dependency, is to manually require-dev symfony/console for 2.8.

    opened by padraic 1
Releases(2.7.5)
Owner
Box Project
An application for building and managing Phars.
Box Project
🔨 Prefixes all PHP namespaces in a file/directory to isolate the code bundled in PHARs.

PHP-Scoper PHP-Scoper is a tool which essentially moves any body of code, including all dependencies such as vendor directories, to a new and distinct

Humbug 590 Jan 2, 2023
A high-performance license server system service for creating and managing products, major versions, and software licenses for the purpose of selling installable software products.

A high-performance license server system service for creating and managing products, major versions, and software licenses for the purpose of selling installable software products. Comes with a SDK and command-line tool. Works anywhere that PHP runs.

CubicleSoft 32 Dec 5, 2022
A simple mini pos that handles managing product data's and product categories

What is CodeIgniter CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable

Mahendra Dwi Purwanto 0 Dec 26, 2021
A tool for managing SSH key access to any number of servers.

Revons - SSH Key Authority Features Easily manage SSH key access for all accounts on your servers. Manage user access and server-to-server access rule

Revons Community 1 Mar 14, 2022
Smd imagery - A Textpattern CMS plugin for managing images in the Write panel.

smd_imagery Insert images into your Write panel. Very handy for people who run photoblog or image-heavy sites, or those who categorise images for incl

Stef Dawson 5 Nov 15, 2022
Sspak - Tool for managing bundles of db/assets from SilverStripe environments

SSPak SSPak is a SilverStripe tool for managing database and assets content, for back-up, restoration, or transfer between environments. The file form

Silverstripe CMS 45 Dec 14, 2022
Version is a library that helps with managing the version number of Git-hosted PHP projects

Version Version is a library that helps with managing the version number of Git-hosted PHP projects. Installation You can add this library as a local,

Sebastian Bergmann 6.3k Dec 26, 2022
PHP daemon for managing gearman workers

Running Gearman workers can be a tedious task. Many many files with the same lines of code over and over for creating a worker, connecting to a server, adding functions to the worker, etc. etc. The aim of GearmanManager is to make running workers more of an operational task and less of a development task.

Brian Moon 684 Dec 5, 2022
TEC UTilities (or tut) are a collection of tools for managing plugins.

TEC Utilities TEC UTilities (or tut) are a collection of tools for managing plugins. /^\ L L /

The Events Calendar 5 Dec 2, 2022
WordPlate is a wrapper around WordPress. It makes developers life easier. It is just like building any other WordPress website with themes and plugins. Just with sprinkles on top.

WordPlate is simply a wrapper around WordPress. It makes developers life easier. It is just like building any other WordPress website with themes and plugins. Just with sprinkles on top.

WordPlate 1.7k Dec 24, 2022
Powerful and flexible component for building site breadcrumbs.

Phalcon Breadcrumbs Phalcon Breadcrumbs is a powerful and flexible component for building site breadcrumbs. You can adapt it to your own needs or impr

Serghei Iakovlev 40 Nov 5, 2022
A minimal library that defines primitive building blocks of PHP code.

Jungi Common A minimal library that defines primitive building blocks of PHP code. It combines the advantages of functional and object-oriented progra

Piotr Kugla 28 Jul 15, 2022
A minimal library that defines primitive building blocks of PHP code.

A minimal library that defines primitive building blocks of PHP code. It combines the advantages of functional and object-oriented programming. All of this makes code easier to understand and less prone to errors.

Jungi 28 Jul 15, 2022
Samsui is a factory library for building PHP objects useful for setting up test data in your applications.

#Samsui Samsui is a factory library for building PHP objects useful for setting up test data in your applications. It is mainly inspired by Rosie for

Sam Yong 31 Nov 11, 2020
A trait to make building your own custom Laravel Model Searches a lot easier.

BrekiTomasson\LaravelModelFinder A simple trait that makes building your own custom Laravel Model Searches a lot easier and safer. It ensures that you

Breki Tomasson 3 Nov 27, 2022
Minimalist PHP frame for Core-Library, for Developing PHP application that gives you the full control of your application.

LazyPHP lightweight Pre-Made Frame for Core-library Install Run the below command in your terminal $ composer create-project ryzen/lazyphp my-first-pr

Ry-Zen 7 Aug 21, 2022
This plugin can be embedded in PHP application to give the web application specific routes/href

Routes Plugin PHP This plugin can be embedded in PHP application to give the web application specific routes/href location and for entering specific/l

Ifechukwudeni Oweh 7 Jul 17, 2022
Issue tracking application extending GitHub's issues and pull requests for the Joomla! project.

Requirements The issue tracker application requires a server running: PHP 7.2 or 7.3 PHP's ext/curl and ext/intl should also be installed MySQL 5.5.3

Joomla! 68 Oct 27, 2022
Sanitize and escape every values in your PHP Application

PHP Sanitizer Sanitize and escape every values in your PHP Application. This solution will make PHP developer life easy, very easy and developers woul

Maniruzzaman Akash 10 Oct 2, 2022