定制 tourze/php-packer-ast 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tourze/php-packer-ast

最新稳定版本:0.0.1

Composer 安装命令:

composer require tourze/php-packer-ast

包简介

AST管理和解析工具

README 文档

README

Latest Stable Version License Build Status

Introduction

PHP Packer AST is a library for parsing, managing, and traversing PHP Abstract Syntax Trees (AST). It provides a simple and extensible API to parse PHP code, manage ASTs, and traverse nodes using the visitor pattern.

Features

  • Parse PHP code and files into AST
  • Efficient AST manager for multiple files
  • Visitor pattern support for flexible AST traversal
  • Simple error handling mechanism
  • Compatible with PHP 8.1 and above

Installation

Require via Composer:

composer require tourze/php-packer-ast

Quick Start

Parse PHP Code

use PhpPacker\Ast\CodeParser;

$parser = new CodeParser();
$ast = $parser->parseCode('<?php echo "Hello World"; ?>');

// Or parse from file
$ast = $parser->parseFile('/path/to/your/file.php');

Use AST Manager

use PhpPacker\Ast\AstManager;
use Psr\Log\NullLogger;

$manager = new AstManager(new NullLogger());

// Add AST
$manager->addAst('/path/to/file.php', $ast);

// Get AST
$ast = $manager->getAst('/path/to/file.php');

// Check existence
if ($manager->hasAst('/path/to/file.php')) {
    // ...
}

// Get statistics
$fileCount = $manager->getFileCount();
$nodeCount = $manager->getTotalNodeCount();

Use Visitor Pattern

use PhpPacker\Ast\Visitor\RenameDebugInfoVisitor;
use PhpParser\NodeTraverser;

$traverser = new NodeTraverser();
$traverser->addVisitor(new RenameDebugInfoVisitor());
$modifiedAst = $traverser->traverse($ast);

Documentation

  • API documentation: See source code and tests
  • Configuration: No additional configuration required
  • Advanced: Implement custom visitors by extending AbstractVisitor

Contribution Guide

  1. Fork and clone this repository
  2. Create a new branch for your feature or bugfix
  3. Write code and add tests
  4. Run tests with PHPUnit
  5. Submit a Pull Request
  • Please follow PSR coding standards
  • Ensure all tests pass before submitting

License

MIT License. See LICENSE for details.

Authors

  • tourze Team

Changelog

See CHANGELOG for release notes and upgrade guide.

统计信息

  • 总下载量: 352
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-11