typhoon/declaration-id
Generate stable, unique IDs for PHP declarations (classes, functions, methods, properties) to track and reference code elements across analyses and tooling. Lightweight package with strict typing and static-analysis-friendly design.
bind('App\Services\Foo', Foo::class) with bind(DeclarationId::of(Foo::class), Foo::class)).laravel/ide-helper by providing stable identifiers for autocompletion.DeclarationIdResolver trait).ServiceProvider bootstrapping).App\Foo → foo or abc123).@inject with generated IDs).| Risk | Severity | Mitigation |
|---|---|---|
| PHP 8.1+ Dependency | High | Enforce PHP 8.1+ in composer.json; test with Laravel 9+/10+. |
| ID Collisions | Medium | Use longer hashes or namespace-qualified IDs (e.g., App\Foo::method). |
| Typhoon Package Instability | Low | Pin to 0.4.x; monitor Typhoon’s GitHub for breaking changes. |
| Performance Overhead | Low | Benchmark in high-load scenarios (e.g., DI container initialization). |
| Lack of Laravel Tooling | Medium | Build custom helpers (e.g., DeclarationIdServiceProvider). |
DeclarationId::of(FooService::class) replace bind('foo_service', ...)?laravel/ide-helper, spatie/laravel-debugbar, or custom profilers.@inject with generated IDs).laravel/ide-helper with stable identifiers.spatie/laravel-debugbar or custom profilers.Phase 1: Proof of Concept (1–2 days)
composer require typhoon/declaration-id.use Typhoon\DeclarationId\DeclarationId;
$id = DeclarationId::of(FooService::class); // e.g., "abc123"
Phase 2: Laravel Integration (3–5 days)
AppServiceProvider:
$this->app->bind(
DeclarationId::of(FooService::class),
FooService::class
);
DeclarationIdHelper to standardize usage:
class DeclarationIdHelper {
public static function bind(string $concrete): void {
$id = DeclarationId::of($concrete);
app()->bind($id, $concrete);
}
}
@inject with generated IDs).Phase 3: Adoption (Ongoing)
| Laravel Component | Compatibility Notes |
|---|---|
| DI Container | Works natively; requires manual ID mapping. |
| Service Providers | Replace bind()/singleton() keys with generated IDs. |
| Macros | Generate stable IDs for macroable classes (e.g., Str::macro()). |
| Blade Templates | Needs custom integration (e.g., @inject with DeclarationId::of(View::class)). |
| Events/Listeners | Useful for stable event class resolution (e.g., Event::dispatch(new FooEvent())). |
| PHP 8.1 Features | Supports enums, attributes, and anonymous classes. |
AppServiceProvider (prioritize high-churn services).DeclarationId::of() usage guidelines).DeclarationId::of() produces duplicates.DeclarationId::debug() method to log IDs during development:
DeclarationId::debug(FooService::class); // Logs: "FooService => abc123"
ServiceProvider bootstrapping:
assert(DeclarationId::of(FooService::class) === 'expected_id');
'foo_service').app() for hot paths (e.g., route resolution).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| ID Collision | Service binding fails. | Use longer hashes or namespace-qualified IDs (e.g., App\Foo::method). |
How can I help you explore Laravel packages today?