PHPackages                             ray/compiler - 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. ray/compiler

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

ray/compiler
============

A dependency injection compiler for Ray.Di

1.13.1(6mo ago)51.8M↓42.2%4[2 issues](https://github.com/ray-di/Ray.Compiler/issues)[2 PRs](https://github.com/ray-di/Ray.Compiler/pulls)5MITPHPPHP ^8.2

Since Apr 27Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/ray-di/Ray.Compiler)[ Packagist](https://packagist.org/packages/ray/compiler)[ RSS](/packages/ray-compiler/feed)WikiDiscussions 1.x Synced 1w ago

READMEChangelog (10)Dependencies (5)Versions (63)Used By (5)

[![logo](https://camo.githubusercontent.com/a826cc4c0b7c71415633f338c0b5a2ec4d121f1b7f6d0b86fe9d3aa265f8ec0a/68747470733a2f2f7261792d64692e6769746875622e696f2f696d616765732f6c6f676f2e737667)](https://camo.githubusercontent.com/a826cc4c0b7c71415633f338c0b5a2ec4d121f1b7f6d0b86fe9d3aa265f8ec0a/68747470733a2f2f7261792d64692e6769746875622e696f2f696d616765732f6c6f676f2e737667)

Ray.Compiler
============

[](#raycompiler)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/43427bc599f5f2536e183373d878714fa4cd40dcf6b03c1f80bb6e115e082048/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7261792d64692f5261792e436f6d70696c65722f6261646765732f7175616c6974792d73636f72652e706e673f623d312e78)](https://scrutinizer-ci.com/g/ray-di/Ray.Compiler/?branch=1.x)[![codecov](https://camo.githubusercontent.com/9df95c73ab47d08f4cdd8430d2b7a0fbfcaeba15e47dece207ed7a54ba1f8b81/68747470733a2f2f636f6465636f762e696f2f67682f7261792d64692f5261792e436f6d70696c65722f6272616e63682f312e782f67726170682f62616467652e7376673f746f6b656e3d4b435158747530317a63)](https://codecov.io/gh/ray-di/Ray.Compiler)[![Type Coverage](https://camo.githubusercontent.com/fc463167ff379d77c5cd393711a3e18bda4d585621883f7485fd8153abce8023/68747470733a2f2f73686570686572642e6465762f6769746875622f7261792d64692f5261792e436f6d70696c65722f636f7665726167652e737667)](https://shepherd.dev/github/ray-di/Ray.Compiler)[![Continuous Integration](https://github.com/ray-di/Ray.Compiler/actions/workflows/continuous-integration.yml/badge.svg?branch=1.x)](https://github.com/ray-di/Ray.Compiler/actions/workflows/continuous-integration.yml)

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
------------

[](#installation)

```
composer require ray/compiler
```

Usage
-----

[](#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

[](#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

[](#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
---------------

[](#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
-------------

[](#documentation)

- **[LLM Documentation](https://ray-di.github.io/Ray.Compiler/llms.txt)** - Brief documentation optimized for LLMs
- **[Complete LLM Documentation](https://ray-di.github.io/Ray.Compiler/llms-full.txt)** - Full documentation with architecture details

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance74

Regular maintenance activity

Popularity47

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 97% 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

Every ~69 days

Recently: every ~5 days

Total

57

Last Release

187d ago

Major Versions

0.3.0 → 1.0.02015-05-21

PHP version history (6 changes)1.1.1PHP &gt;=5.6.0

1.1.7PHP &gt;=7.1.0

1.2.1PHP &gt;=7.0.0

1.4.1PHP &gt;=7.2.0

1.6.0PHP ^7.2 || ^8.0

1.13.0PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![koriym](https://avatars.githubusercontent.com/u/529021?v=4)](https://github.com/koriym "koriym (797 commits)")[![NaokiTsuchiya](https://avatars.githubusercontent.com/u/17171732?v=4)](https://github.com/NaokiTsuchiya "NaokiTsuchiya (18 commits)")[![jingu](https://avatars.githubusercontent.com/u/892913?v=4)](https://github.com/jingu "jingu (3 commits)")[![apple-x-co](https://avatars.githubusercontent.com/u/8497012?v=4)](https://github.com/apple-x-co "apple-x-co (2 commits)")[![fiahfy](https://avatars.githubusercontent.com/u/7123916?v=4)](https://github.com/fiahfy "fiahfy (2 commits)")

---

Tags

codegencompilerdependency-injectionphpray-didicodegensrc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ray-compiler/health.svg)

```
[![Health](https://phpackages.com/badges/ray-compiler/health.svg)](https://phpackages.com/packages/ray-compiler)
```

###  Alternatives

[bear/package

BEAR.Sunday application framework package

30553.3k25](/packages/bear-package)[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

437773.0k19](/packages/level-2-dice)[hyperf/di

A DI for Hyperf.

172.9M629](/packages/hyperf-di)[ray/media-query

PHP interface-based SQL framework

11242.8k2](/packages/ray-media-query)[x-wp/di

The dependency injection container for WordPress

314.2k13](/packages/x-wp-di)

PHPackages © 2026

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