Skip to content

Commit

Permalink
Simplify README with updated instruction for injections
Browse files Browse the repository at this point in the history
The README.md has been simplified with outdated sections removed. Information regarding `DiCompiler`, `CompileInjector` and object graph visualization has been removed as it is no longer necessary or applicable. The revised instructions now focus on using `CompileInjector` for injecting a `CarModule` and compiling dependencies before production.
  • Loading branch information
koriym committed May 23, 2024
1 parent 91dcb03 commit 2575537
Showing 1 changed file with 4 additions and 39 deletions.
43 changes: 4 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,16 @@

Ray.Compiler compiles Ray.Di bindings into PHP code, providing a performance boost that makes Dependency Injection couldn't be any faster.

Ray.Compiler injector
```php
$injector = new ScriptInjector($tmpDir, fn => new CarModule);
$injector = new CompileInjector($tmpDir, fn => new CarModule);
$car = $injector->getInstance(CarInterface::class);
```

## Precompile

You will want to compile all dependencies into code before deploying the production. The `DiCompiler` will compile all bindings into PHP code.
You will want to compile all dependencies into code before deploying the production.

```php
$compiler = new DiCompiler(new CarModule, $tmpDir);
$compiler = new Compiler($tmpDir, new CarModule);
$compiler->compile();
```

## Object graph visualization

Object graph can be visualized with `dumpGraph()`.
Graph HTML files will be output at `graph` folder under `$tmpDir`.

```php
$compiler = new DiCompiler(new Module, $tmpDir);
$compiler->compile();
$compiler->dumpGraph();
```

```
open tmp/graph/Ray_Compiler_FakeCarInterface-.html
```

## CompileInjector

The `CompileInjector` gives you the best performance in both development (x2) and production (x10) by switching two injector.

Get the injector by specifying the binding and cache, depending on the execution context of the application.

```php
$injector = new CompileInjector($tmpDir, $injectorContext);
```

`$injectorContext` example:

* [dev](docs/exmaple/DevInjectorContext.php)
* [prod](docs/exmaple/ProdInjectorContext.php)

The `__invoke()` method prepares the modules needed in that context.
The `getCache()` method specifies the cache of the injector itself.

Install `DiCompileModule` in the context for production. The injector is more optimized and dependency errors are reported at compile-time instead of run-time.

0 comments on commit 2575537

Please sign in to comment.