fix: resolve #[ScriptDir] to __DIR__ instead of baking the compile-time absolute path#136
Conversation
…me path Ray\Di\Annotation\ScriptDir and Ray\Di\InjectorInterface were bound via CompilerModule::toInstance() with the compile-time absolute scriptDir, so both got var_export()'d as a string literal into every generated script that pulled either binding into the object graph (e.g. via assisted injection or multibinding, which require InjectorInterface internally). Moving the compiled scripts to a different absolute path after compilation (immutable images, CI build vs. runtime path, etc.) either threw ScriptDirNotReadable or silently resolved against a stale path. Since generated scripts always live inside scriptDir, __DIR__ at require-time is always correct. Special-case the ScriptDir binding's container key in InstanceScript::addArg() and Compiler::compile()'s map() callback to emit __DIR__ instead of the baked path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthrough
ChangesScriptDir Relocation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant Test
participant CompiledInjector
participant GeneratedScript
participant Consumer
Test->>CompiledInjector: load relocated compiled output
CompiledInjector->>GeneratedScript: resolve ScriptDir binding
GeneratedScript-->>CompiledInjector: return __DIR__
CompiledInjector->>Consumer: inject runtime directory
Consumer-->>Test: return script directory
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 1.x #136 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 93 95 +2
===========================================
Files 11 11
Lines 232 238 +6
===========================================
+ Hits 232 238 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
ScriptDir(andInjectorInterface, which requires it) wasvar_export()'d into generated scripts as a literal build-time path, breaking when the compiled directory is moved (immutable images, CI build path != runtime path, etc.).Since scripts always run from inside
scriptDir, emit__DIR__instead of the baked path.Added
tests/ScriptDirRelocationTest.php: compiles, relocates the directory, and asserts ctor/setter/provider/AOP bindings +InjectorInterfaceall still resolve, and no generated script contains the old path. Confirmed the test fails without the fix.Summary by CodeRabbit
Bug Fixes
Tests