Phar Compact
, (*1)
Integrates the compact library with the phar library., (*2)
Requirement
Installation
Via Composer:, (*3)
$ 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:, (*4)
Builder::ADD_FILE
Builder::ADD_STRING
To create an observer, you will need a new instance of CompactObserver
., (*5)
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., (*6)
Documentation
You can find the API documentation here., (*7)
License
This library is available under the MIT license., (*8)