PHPackages                             tourze/php-packer - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tourze/php-packer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tourze/php-packer
=================

A PHP library for analyzing, packing and merging PHP files using AST storage

0.0.1(6mo ago)20MITPHPCI passing

Since Nov 14Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/tourze/php-packer)[ Packagist](https://packagist.org/packages/tourze/php-packer)[ RSS](/packages/tourze-php-packer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (2)Used By (0)

PHP Packer
==========

[](#php-packer)

[![PHP Version](https://camo.githubusercontent.com/2ee6a1ac1ae197d71438a2866804a3ad085ec16910274b539f36a47deb17868a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d3737374242343f7374796c653d666c61742d737175617265)](https://php.net/)[![License](https://camo.githubusercontent.com/ac049ef4e7a0b7196b09add6ac2d4f180e544c0ac779c2b2ac2fd2723a209579/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75653f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/71c899315a8f155d504bb23baebabdd724ea15a42a5f7e72e49e6b4e9ebc30d3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f746573742e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/6ce0146325478eb7cebae4cc6139b2af2c161735dd0e3c6ff6802f2c5a708179/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/php-monorepo)

[English](README.md) | [中文](README.zh-CN.md)

A PHP single-file packer that packages PHP projects into a single executable file.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
    - [Basic Workflow](#basic-workflow)
- [Available Commands](#available-commands)
    - [analyze - Analyze PHP Project](#analyze-analyze-php-project)
    - [dependencies - Query Dependencies](#dependencies-query-dependencies)
    - [files - List All Files](#files-list-all-files)
    - [pack - Pack Project](#pack-pack-project)
    - [Complete Example](#complete-example)
- [Configuration](#configuration)
- [How It Works](#how-it-works)
- [Examples](#examples)
- [Advanced Usage](#advanced-usage)
- [Limitations](#limitations)
- [Development](#development)
- [License](#license)

Features
--------

[](#features)

- Automatic PHP file dependency analysis
- Support for PSR-4/PSR-0 autoloading standards
- Use SQLite to store and query dependency relationships
- Intelligent parsing of require/include statements
- Handle class inheritance, interface implementation, and trait usage
- Generate optimized bootstrap code
- Support for conditional dependencies and circular dependency detection
- Modular command design with step-by-step operations

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

[](#installation)

```
composer require tourze/php-packer
```

Quick Start
-----------

[](#quick-start)

### Basic Workflow

[](#basic-workflow)

```
# 1. Analyze project and generate dependency database
php vendor/bin/php-packer analyze src/index.php --database=build/app.db

# 2. View analysis results
php vendor/bin/php-packer files --database=build/app.db --stats

# 3. Query dependencies for specific files
php vendor/bin/php-packer dependencies src/Application.php --database=build/app.db --tree

# 4. Pack into single file
php vendor/bin/php-packer pack --database=build/app.db --output=dist/app.php
```

Available Commands
------------------

[](#available-commands)

### analyze - Analyze PHP Project

[](#analyze---analyze-php-project)

Analyze entry file and generate dependency database.

```
php-packer analyze  [options]

Options:
  --database, -d     Database file path (default: ./packer.db)
  --root-path, -r    Project root path (default: current directory)
  --composer, -c     Composer.json path (default: /composer.json)
  --autoload         Additional autoload config in format "psr4:prefix:path"
  --help, -h         Show help message

Examples:
  php-packer analyze index.php
  php-packer analyze src/app.php --database=build/myapp.db
  php-packer analyze index.php --autoload="psr4:MyLib:lib/"
```

### dependencies - Query Dependencies

[](#dependencies---query-dependencies)

Query and display file dependencies.

```
php-packer dependencies  [options]

Options:
  --database, -d     Database file path (default: ./packer.db)
  --root-path, -r    Project root path (default: current directory)
  --reverse          Show files that depend on this file
  --tree             Display in tree structure
  --help, -h         Show help message

Examples:
  php-packer dependencies src/Controller.php
  php-packer dependencies src/Model.php --reverse
  php-packer dependencies src/Application.php --tree
```

### files - List All Files

[](#files---list-all-files)

List all files and their information in the database.

```
php-packer files [options]

Options:
  --database, -d     Database file path (default: ./packer.db)
  --root-path, -r    Project root path (default: current directory)
  --type, -t         Filter by type (class, trait, interface, script)
  --stats            Show only statistics
  --entry            Show only entry files
  --sort             Sort by: name, type, size, dependencies (default: name)
  --help, -h         Show help message

Examples:
  php-packer files --stats
  php-packer files --type=class
  php-packer files --sort=dependencies
```

### pack - Pack Project

[](#pack---pack-project)

Read analysis results from database and generate packed file.

```
php-packer pack [options]

Options:
  --database, -d     Database file path (default: ./packer.db)
  --root-path, -r    Project root path (default: current directory)
  --output, -o       Output file path (default: ./packed.php)
  --compression      Enable output compression (gzip)
  --strip-comments   Remove code comments
  --optimize         Enable code optimization
  --help, -h         Show help message

Examples:
  php-packer pack --output=dist/app.php
  php-packer pack --strip-comments --optimize
  php-packer pack --output=app.phar --compression
```

### Complete Example

[](#complete-example)

Packing a Laravel application:

```
# Analyze
php-packer analyze public/index.php \
  --database=build/laravel.db \
  --root-path=/path/to/laravel

# View statistics
php-packer files --database=build/laravel.db --stats

# Pack
php-packer pack \
  --database=build/laravel.db \
  --output=dist/laravel-packed.php \
  --strip-comments \
  --optimize
```

How It Works
------------

[](#how-it-works)

1. **Initialization Phase**

    - Create SQLite database
    - Load autoload rules from composer.json
    - Parse configuration files
2. **Analysis Phase**

    - Start analysis from entry file
    - Parse AST using PHP Parser
    - Extract all dependency relationships
    - Iteratively analyze all related files
3. **Resolution Phase**

    - Build dependency graph
    - Resolve symbol references
    - Detect circular dependencies
    - Determine file loading order
4. **Packing Phase**

    - Generate bootstrap code
    - Merge files in dependency order
    - Optimize output code
    - Generate single PHP file

Configuration
-------------

[](#configuration)

The packer can be configured through various options:

### Database Options

[](#database-options)

- `--database, -d`: Specify SQLite database file path
- Default: `./packer.db`

### Path Options

[](#path-options)

- `--root-path, -r`: Set project root directory
- `--composer, -c`: Specify composer.json file location
- `--autoload`: Add custom autoload rules in format "psr4:prefix:path"

### Output Options

[](#output-options)

- `--output`: Specify output file path for packed result
- `--strip-comments`: Remove comments from packed file
- `--optimize`: Enable code optimization

### Example Configuration

[](#example-configuration)

```
php-packer analyze src/app.php \
  --database=build/app.db \
  --root-path=/path/to/project \
  --composer=composer.json \
  --autoload="psr4:MyApp\\:src/"
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Autoloading

[](#custom-autoloading)

You can add custom PSR-4 or PSR-0 autoload rules:

```
php-packer analyze src/app.php \
  --autoload="psr4:Custom\\Namespace\\:custom/src/" \
  --autoload="psr0:Legacy_:legacy/lib/"
```

### Optimization Options

[](#optimization-options)

Enable various optimizations during packing:

```
php-packer pack \
  --database=build/app.db \
  --output=dist/optimized-app.php \
  --strip-comments \
  --optimize
```

### Dependency Analysis

[](#dependency-analysis)

Query and analyze dependencies for debugging:

```
# Show dependency tree for a specific file
php-packer dependencies src/Controller/HomeController.php \
  --database=build/app.db \
  --tree

# List all files with statistics
php-packer files --database=build/app.db --stats
```

Examples
--------

[](#examples)

Check the complete examples in the `examples/` directory:

```
cd packages/php-packer
php bin/php-packer examples/packer-config.json
```

This will pack the example project into `build/packed.php`.

Limitations
-----------

[](#limitations)

- Does not support dynamic includes (e.g., `require $file`)
- Does not support code in eval()
- Requires PHP 8.1+
- Some PHP extensions may need special handling

Development
-----------

[](#development)

Run tests:

```
vendor/bin/phpunit
```

Code quality check:

```
vendor/bin/phpstan analyse src/
```

License
-------

[](#license)

MIT

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance71

Regular maintenance activity

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

186d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

---

Tags

packerphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-php-packer/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-php-packer/health.svg)](https://phpackages.com/packages/tourze-php-packer)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[tempest/framework

The PHP framework that gets out of your way.

2.1k23.1k9](/packages/tempest-framework)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[bartlett/php-compatinfo

Find out the minimum version and the extensions required for a piece of code to run

38298.7k7](/packages/bartlett-php-compatinfo)

PHPackages © 2026

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