PHPackages                             tourze/php-packer-generator - 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-generator

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

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

代码生成工具，用于PHP代码的合并、优化和格式控制

0.0.1(1y ago)06MITPHPPHP ^8.1CI passing

Since Apr 17Pushed 11mo ago1 watchersCompare

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

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

PHP-Packer-Generator
====================

[](#php-packer-generator)

[![Latest Version](https://camo.githubusercontent.com/6430a5eef38755d760bc0e721f05537c9823f8218333cb971e7ea41df090d75f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f7068702d7061636b65722d67656e657261746f722e737667)](https://packagist.org/packages/tourze/php-packer-generator)[![Build Status](https://github.com/tourze/php-packer-generator/workflows/CI/badge.svg)](https://github.com/tourze/php-packer-generator/actions)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

The **PHP-Packer-Generator** is a code generation component for the PHP-Packer project, responsible for merging, optimizing, and formatting PHP code.

Features
--------

[](#features)

- **Code Merging**: Merge multiple PHP files into a single file.
- **Code Optimization**: Support for code minification, comment preservation, and more.
- **Output Formatting**: Control the formatting and style of the generated code.
- **Resource Embedding**: Generate code to embed resource files.
- **Highly Extensible**: Support custom code optimizers and formatters.

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

[](#installation)

Requirements:

- PHP &gt;= 8.1
- Composer

Install via Composer:

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

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

[](#quick-start)

Basic usage example:

```
use PhpPacker\Generator\CodeGenerator;
use PhpPacker\Generator\Config\GeneratorConfig;
use PhpPacker\Ast\AstManager;
use Psr\Log\LoggerInterface;

// Create config
$config = new GeneratorConfig();
$config->setPreserveComments(true);
$config->setRemoveNamespace(false);

// Create code generator
$astManager = new AstManager($logger); // $logger must implement LoggerInterface
$generator = new CodeGenerator($config, $astManager, $logger);

// Generate code
$code = $generator->generate($astManager, $phpFiles, $resourceFiles);
```

Custom Code Generation
----------------------

[](#custom-code-generation)

You can extend the code generation process by implementing your own `CodeOptimizer` and `CodeFormatter`:

```
use PhpPacker\Generator\Optimizer\CustomOptimizer;
use PhpPacker\Generator\Formatter\CustomFormatter;

$optimizer = new CustomOptimizer();
$formatter = new CustomFormatter();

$generator = new CodeGenerator($config, $astManager, $logger, $optimizer, $formatter);
```

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

[](#configuration)

The `GeneratorConfig` class provides options to control code generation:

- `setPreserveComments(bool $preserve)`: Whether to keep comments.
- `setRemoveNamespace(bool $remove)`: Whether to remove namespaces (useful for KPHP compatibility).
- `setOptimizeCode(bool $optimize)`: Enable/disable code optimization.
- `setLineEnding(?string $ending)`: Set custom line ending (e.g., `"\r\n"`).
- `setIndentationSize(int $size)`: Set indentation size.
- `setIndentationChar(string $char)`: Set indentation character (e.g., space or tab).

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

[](#advanced-usage)

- **Resource Embedding**: Use `ResourceHolderGenerator` to generate code for resource files.
- **Custom Visitors**: Implement your own AST visitors for advanced code transformations.

Contribution Guide
------------------

[](#contribution-guide)

- Please submit issues and pull requests via GitHub.
- Follow PSR code style guidelines.
- Ensure all tests pass (`phpunit`).
- Add tests for new features.

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

Changelog
---------

[](#changelog)

See [Releases](https://github.com/tourze/php-packer-generator/releases) for version history and upgrade notes.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance49

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

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

388d 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)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k17](/packages/civicrm-civicrm-core)[j0k3r/php-readability

Automatic article extraction from HTML

186808.8k6](/packages/j0k3r-php-readability)[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)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k134](/packages/symfony-ai-platform)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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