定制 thomasmarinissen/class-dependency-resolver 二次开发

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

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

thomasmarinissen/class-dependency-resolver

Composer 安装命令:

composer require thomasmarinissen/class-dependency-resolver

包简介

A Class Dependency Resolver for PHP

README 文档

README

Description

The PHP Class Dependency Resolver is a library designed to facilitate providing context to Large Language Models by resolving dependencies of PHP classes/files. It maps fully qualified class names, interfaces, and traits to their corresponding file paths and manages the direct dependencies between files. The main entry point to the library is the Resolver class.

Table of Contents

Installation

To install the Class Dependency Resolver library, use Composer:

composer require thomasmarinissen/class-dependency-resolver

Ensure that your PHP version is compatible (PHP 8.3 or higher) and that you have Composer installed on your system.

Basic Usage

To use the Class Dependency Resolver, you need to initialize the Resolver class with the directories you want to scan for PHP files. Here is a basic example:

use Thomasmarinissen\ClassDependencyResolver\Resolver;

// Directories to scan
$directories = ['/path/to/your/php/files'];

// Initialize the Resolver
$resolver = new Resolver($directories);

// Get the file path for a specific class
$filePath = $resolver->filePathByName('Your\Namespace\YourClass');

// Get the dependencies for a specific file
$dependencies = $resolver->dependenciesByFile('/path/to/your/php/files/YourClass.php');

This example demonstrates how to initialize the resolver, build the dependency maps, and retrieve file paths and dependencies.

Configuration

The Resolver class allows you to specify the PHP version you want to target when parsing files. By default, it uses the host's PHP version. You can specify a different version by passing a PhpVersion instance to the constructor:

use PhpParser\PhpVersion;
use Thomasmarinissen\ClassDependencyResolver\Resolver;

// Specify PHP version
$phpVersion = PhpVersion::fromString('8.3');

// Initialize the Resolver with a specific PHP version
$resolver = new Resolver(['/path/to/your/php/files'], $phpVersion);

This allows you to ensure compatibility with different PHP versions when resolving dependencies.

Examples

Example 1: Resolving Class Dependencies

use Thomasmarinissen\ClassDependencyResolver\Resolver;

$directories = ['/path/to/your/php/files'];
$resolver = new Resolver($directories);

$className = 'App\Controllers\HomeController';
$filePath = $resolver->filePathByName($className);
$dependencies = $resolver->dependenciesByName($className);

echo "File path for $className: $filePath\n";
echo "Dependencies: " . implode(', ', $dependencies) . "\n";

Example 2: Handling Multiple Directories

use Thomasmarinissen\ClassDependencyResolver\Resolver;

$directories = ['/path/to/first/directory', '/path/to/second/directory'];
$resolver = new Resolver($directories);

$filePath = $resolver->filePathByName('Another\Namespace\AnotherClass');

echo "File path: $filePath\n";

Example 3: Resolving Class Dependencies by file path

use Thomasmarinissen\ClassDependencyResolver\Resolver;

$directories = ['/path/to/first/directory'];
$resolver = new Resolver($directories);

$filePath = '/path/to/first/directory/AnotherClass.php';

$dependencies = $resolver->dependenciesByFile($filePath);

echo "Dependencies: " . implode(', ', $dependencies) . "\n";

These examples illustrate how to resolve dependencies for classes or files and handle multiple directories.

Contributing

Contributions are welcome! If you wish to contribute to the Class Dependency Resolver project, please follow these guidelines:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Make your changes and ensure that all tests pass.
  4. Submit a pull request with a clear description of your changes.

Please adhere to the coding standards and include tests for any new functionality.

Testing

To run the tests for the Class Dependency Resolver library, you need to have PHPUnit installed. You can run the tests using the following command:

composer test

This command will execute the PHPUnit tests defined in the tests directory. Ensure that all tests pass before submitting any contributions.

License

This project is licensed under the MIT License - see the LICENSE file for details.

thomasmarinissen/class-dependency-resolver 适用场景与选型建议

thomasmarinissen/class-dependency-resolver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 thomasmarinissen/class-dependency-resolver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 thomasmarinissen/class-dependency-resolver 我们能提供哪些服务?
定制开发 / 二次开发

基于 thomasmarinissen/class-dependency-resolver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-25