PHPackages                             phine/compact - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. phine/compact

AbandonedArchivedLibrary[File &amp; Storage](/categories/file-storage)

phine/compact
=============

A PHP library for compacting the contents of files.

1.1.0(12y ago)45811MITPHPPHP &gt;=5.3.3

Since Dec 8Pushed 12y agoCompare

[ Source](https://github.com/kherge-archive/lib-compact)[ Packagist](https://packagist.org/packages/phine/compact)[ Docs](https://github.com/phine/lib-compact)[ RSS](/packages/phine-compact/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (3)Versions (3)Used By (1)

Compact
=======

[](#compact)

[![Build Status](https://camo.githubusercontent.com/48a8e95b70f31ba9e2177e791d5203d5e552b837a9bf3cd921bc9570d574f89a/68747470733a2f2f7472617669732d63692e6f72672f7068696e652f6c69622d636f6d706163742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/phine/lib-compact)[![Coverage Status](https://camo.githubusercontent.com/649249bb61ced1b6c3fc793beba88a3c5b7ed6bcc67efb45d1893eabeecc11d6/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7068696e652f6c69622d636f6d706163742f62616467652e706e67)](https://coveralls.io/r/phine/lib-compact)[![Latest Stable Version](https://camo.githubusercontent.com/b87752cf511c8f7d6fce984bcb2acb1adc83ce62c4472796b3642110fc0328db/68747470733a2f2f706f7365722e707567782e6f72672f7068696e652f636f6d706163742f762f737461626c652e706e67)](https://packagist.org/packages/phine/compact)[![Total Downloads](https://camo.githubusercontent.com/be3ffb57fd0f27c8113292c6b0079d211e9bd66826e600d92b803f770e527428/68747470733a2f2f706f7365722e707567782e6f72672f7068696e652f636f6d706163742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/phine/compact)

A PHP library for compacting the contents of files.

Requirement
-----------

[](#requirement)

- PHP &gt;= 5.3.3
- [Phine Exception](https://github.com/phine/lib-exception) &gt;= 1.0.0

Installation
------------

[](#installation)

Via [Composer](http://getcomposer.org/):

```
$ composer require "phine/compact=~1.0"

```

Usage
-----

[](#usage)

The Compact library provides a consistent way of compacting files and their contents. The purpose of the library is simply to reduce the size of the contents without affecting how it is used. For example, compacting a JSON file would involve removing any excess whitespace that was used for "pretty printing".

```
use Phine\Compact\Json;

$compactor = new Json();

echo $compactor->compactFile('example.json');

// which is also the same as

echo $compactor->compactContents(file_get_contents('example.json'));
```

Assuming we had this in `example.json`:

```
{
    "name": 123
}
```

The contents would then be compacted to:

```
{"name":123}
```

### Bundled Compactors

[](#bundled-compactors)

The library also includes the following compactor classes:

- `Phine\Compact\Json` — For compacting JSON files.
- `Phine\Compact\Php` — For compacting PHP files.
- `Phine\Compact\Xml` — For compacting XML files.

### Creating a Compactor

[](#creating-a-compactor)

The library includes an interface that all bundled classes implement. An abstract class is also included, which all bundled compactor classes extend. When you create your own compactor class, you will want to extend the `Phine\Compact\AbstractCompact` class.

```
use Phine\Compact\AbstractCompact;

/**
 * Simply trims all lines.
 */
class Trim extends AbstractCompact
{
    /**
     * {@inheritDoc}
     */
    public function compactContents($contents)
    {
        $contents = preg_replace('/^\s+/m', '', $contents);
        $contents = preg_replace('/\s+$/m', '', $contents);

        return $contents;
    }
}
```

When extending the `AbstractCompact` class, the `compactFile()` method will already be implemented for you. It will rely on the `compactContents()` method to compact the contents after it has been read from the file.

> Please considering adding your compactor class to [the wiki](https://github.com/phine/lib-compact/wiki).

### Collections

[](#collections)

If you need to manage multiple compactors, the library offers a `Collection`class. In addition to the class, an interface is provided so that different implementations can be supported.

```
use Phine\Compact\Collection;
use Phine\Compact\Json;
use Phine\Compact\Php;
use Phine\Compact\Xml;

$collection = new Collection();
$collection->addCompactor(new Json());
$collection->addCompactor(new Php());
$collection->addCompactor(new Xml());

$json = compactContents($json);
// {"key":"value"}
```

Documentation
-------------

[](#documentation)

You can find the API [documentation here](http://phine.github.io/lib-compact).

License
-------

[](#license)

This library is available under the [MIT license](LICENSE).

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~29 days

Total

2

Last Release

4512d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9122157?v=4)[Kevin Herrera](/maintainers/kherge)[@kherge](https://github.com/kherge)

---

Top Contributors

[![kherge](https://avatars.githubusercontent.com/u/9122157?v=4)](https://github.com/kherge "kherge (8 commits)")

---

Tags

compact

### Embed Badge

![Health badge](/badges/phine-compact/health.svg)

```
[![Health](https://phpackages.com/badges/phine-compact/health.svg)](https://phpackages.com/packages/phine-compact)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
