Integrates the compact library with the phar library.

1.0.0 2014-01-08 15:26 UTC


Build Status Coverage Status Latest Stable Version Total Downloads

Integrates the compact library with the phar library.



Via Composer:

$ composer require "phine/phar-compact=~1.0"


The library provides a single subject observer for lib-phar. This observer can be registered to the following subjects in order to compact file contents as they are being added to the archive:

  • Builder::ADD_FILE
  • Builder::ADD_STRING

To create an observer, you will need a new instance of CompactObserver.

use Phine\Compact;
use Phine\Compact\Collection;
use Phine\Phar\Builder;
use Phine\Phar\Compact\CompactObserver;

// create the archive builder
$builder = Builder::create('example.phar');

// create the collection of compactors
$collection = new Collection();
$collection->addCompactor(new Compact\Json());
$collection->addCompactor(new Compact\Php());
$collection->addCompactor(new Compact\Xml());

// create the compactor observer
$observer = new CompactObserver($collection);

// register it with the builder subjects
$builder->observe(Builder::ADD_FILE, $observer);
$builder->observe(Builder::ADD_STRING, $observer);

With the observer registered, any time a file is added to the archive via the addFile() or addFromString() methods, the contents of the supported file types will be automatically compacted before being added to the archive.


You can find the API documentation here.


This library is available under the MIT license.