承接 ray/compiler 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ray/compiler

最新稳定版本:1.13.1

Composer 安装命令:

composer require ray/compiler

包简介

A dependency injection compiler for Ray.Di

README 文档

README

logo

Ray.Compiler

Scrutinizer Code Quality codecov Type Coverage Continuous Integration

Pre-compile Ray.Di bindings to PHP code for maximum performance. The compiled injector runs faster than the standard injector by avoiding runtime reflection and binding resolution.

Installation

composer require ray/compiler

Usage

Ray.Compiler provides two main components:

  1. Compiler: Compiles Ray.Di bindings into PHP code.
  2. CompiledInjector: High-performance injector that executes pre-compiled code.

Basic Usage

Pre-compile your dependencies:

use Ray\Compiler\Compiler;

$compiler = new Compiler();
// Compile Ray.Di bindings to PHP files
$compiler->compile(
    $module,    // AbstractModule: Your application's module
    $scriptDir  // string: Directory path where compiled PHP files will be generated
);

Use the compiled injector:

use Ray\Compiler\CompiledInjector;

$injector = new CompiledInjector($scriptDir);
$instance = $injector->getInstance(YourInterface::class);

Compiler Integration

Create a compile script:

try {
    $scripts = (new Compiler())->compile(
        new AppModule(),
        __DIR__ . '/di'
    );
    printf("Compiled %d files.\n", count($scripts));
} catch (CompileException $e) {
    fprintf(STDERR, "Compilation failed: %s\n", $e->getMessage());
    exit(1);
}

Add compile script to your composer.json:

{
    "scripts": {
        "post-install-cmd": ["php bin/compile.php"]
    }
}

Version Control

Compiled DI code is considered an environment-specific build artifact and should not be committed to version control. This approach ensures that your repository remains clean and build artifacts do not cause merge conflicts or unexpected behavior across different environments.

Add the compile directory to your .gitignore:

/tmp/di/

Documentation

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-26