|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Ray.Di is a dependency injection and AOP (Aspect-Oriented Programming) framework for PHP inspired by Google Guice. It provides annotations-based dependency injection with support for AOP interceptors. |
| 8 | + |
| 9 | +## Core Architecture |
| 10 | + |
| 11 | +### Key Components |
| 12 | +- **AbstractModule**: Base class for defining dependency bindings. Modules are composed using `install()` and can be overridden using `override()` |
| 13 | +- **Injector**: Main entry point that manages the DI container and creates instances. Auto-registers generated proxy classes and handles untargeted bindings |
| 14 | +- **Bind**: Fluent API for creating bindings (`.to()`, `.toProvider()`, `.toInstance()`, `.in()`) |
| 15 | +- **Container**: Internal storage for all bindings and dependencies |
| 16 | +- **Annotations**: Located in `src/di/Di/` - includes `@Inject`, `@Named`, `@Assisted`, etc. |
| 17 | + |
| 18 | +### Directory Structure |
| 19 | +- `src/di/`: Core DI framework code |
| 20 | +- `src-deprecated/`: Legacy code maintained for compatibility |
| 21 | +- `tests/di/`: Unit tests with extensive fake classes for testing |
| 22 | +- `demo/` and `demo-php8/`: Examples showing framework usage |
| 23 | +- Compiled proxy classes are cached in configurable temp directories |
| 24 | + |
| 25 | +## Development Commands |
| 26 | + |
| 27 | +### Testing |
| 28 | +```bash |
| 29 | +composer test # Run PHPUnit tests |
| 30 | +composer coverage # Generate test coverage with Xdebug |
| 31 | +composer pcov # Generate coverage with PCOV (faster) |
| 32 | +``` |
| 33 | + |
| 34 | +### Code Quality |
| 35 | +```bash |
| 36 | +composer cs # Run PHP_CodeSniffer |
| 37 | +composer cs-fix # Auto-fix coding standards |
| 38 | +composer sa # Static analysis (Psalm + PHPStan) |
| 39 | +composer clean # Clear analysis caches |
| 40 | +``` |
| 41 | + |
| 42 | +### Build Pipeline |
| 43 | +```bash |
| 44 | +composer build # Full build: cs + sa + pcov + metrics |
| 45 | +composer tests # Quick check: cs + sa + test |
| 46 | +``` |
| 47 | + |
| 48 | +### Analysis Tools |
| 49 | +```bash |
| 50 | +composer phpmd # PHP Mess Detector |
| 51 | +composer metrics # Generate code metrics |
| 52 | +composer baseline # Update static analysis baselines |
| 53 | +``` |
| 54 | + |
| 55 | +## Testing Strategy |
| 56 | + |
| 57 | +- Tests use extensive fake classes in `tests/di/Fake/` to simulate real-world scenarios |
| 58 | +- Supports both PHP 7.2+ and PHP 8+ with separate test suites |
| 59 | +- Cache files are automatically cleaned between test runs |
| 60 | +- AOP proxy generation is tested with temporary directories |
| 61 | + |
| 62 | +## Framework Patterns |
| 63 | + |
| 64 | +### Module Definition |
| 65 | +```php |
| 66 | +class MyModule extends AbstractModule |
| 67 | +{ |
| 68 | + protected function configure(): void |
| 69 | + { |
| 70 | + $this->bind(Interface::class)->to(Implementation::class); |
| 71 | + $this->bind(Service::class)->toProvider(ServiceProvider::class); |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +### Injection Usage |
| 77 | +```php |
| 78 | +$injector = new Injector(new MyModule()); |
| 79 | +$instance = $injector->getInstance(Interface::class); |
| 80 | +``` |
| 81 | + |
| 82 | +## Important Notes |
| 83 | + |
| 84 | +- Ray.Di generates proxy classes for AOP which are cached in temp directories |
| 85 | +- The framework supports both constructor and setter injection |
| 86 | +- All bindings are resolved at runtime with automatic proxy weaving for aspects |
| 87 | +- Multi-binding support allows collecting multiple implementations of the same interface |
0 commit comments