Home

Awesome

Phar Compact

Build Status Coverage Status Latest Stable Version Total Downloads

Integrates the compact library with the phar library.

Requirement

Installation

Via Composer:

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

Usage

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:

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.

Documentation

You can find the API documentation here.

License

This library is available under the MIT license.