dragon-code/contracts
Dragon Code Contracts provides a lightweight set of PHP interfaces (contracts) you can reuse across any project to standardize key behaviors, improve type-safety, and keep implementations decoupled. Ideal as a shared dependency for packages and applications.
Cache\Store, Queue\ShouldQueue, and Dtoable mirror Laravel’s built-in patterns, enabling zero-boilerplate adoption for common use cases.Cache\Ttl, Http\Builder). This allows teams to decouple business logic from infrastructure, simplifying future migrations (e.g., switching cache drivers or HTTP clients).symfony/http-kernel), ensuring interoperability with modern PHP ecosystems while maintaining Laravel-specific extensions (e.g., rememberForever for caching).ActionInterface and ShouldBeUnique align with DDD principles, enabling bounded context isolation and event-driven workflows without framework lock-in.MigrateDatabase facilitating database-agnostic migrations.class MyDto implements Dtoable).Cache\Store) are backward-compatible with older versions, reducing migration risks.ShouldQueue::getQueue()).Illuminate\Contracts\Cache\Store) but extend them, avoiding conflicts with existing implementations.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Breaking Changes | Minor updates (e.g., Symfony 7.0 bump in v2.22.0) may require dependency updates, but major versions follow semver. | Lock to a stable minor version (e.g., ^2.25) and monitor Laravel/Symfony compatibility. |
| Overhead for Small Projects | Contracts add minimal value for projects with <5K LoC or no modularity goals. | Opt-in adoption: Start with high-impact contracts (e.g., Dtoable, ShouldQueue) and expand as needed. |
| Laravel Version Lock-In | Contracts are Laravel-centric (e.g., rememberForever for cache). |
Use adapter patterns to abstract Laravel-specific logic if portability is critical. |
| Testing Complexity | Interfaces like Cache\Store may increase mocking effort in unit tests. |
Leverage Laravel’s built-in mocking tools (e.g., Mockery) or DragonCode’s testing utilities (if part of the ecosystem). |
| Ecosystem Dependency | Some contracts (e.g., Dtoable) assume DragonCode/helpers for full functionality. |
Document optional dependencies and provide fallback implementations for standalone use. |
| Performance Impact | Zero runtime overhead, but compile-time checks may slow development environments. | Exclude contracts from production builds (if using PHP 8.2+) or use opcache to mitigate. |
Architecture Goals:
Team Maturity:
Ecosystem Integration:
Dtoable are required for full functionality.Migration Strategy:
implements Dtoable) or start fresh in new modules?Long-Term Maintenance:
Testing Impact:
ShouldQueue jobs behave as expected)?Performance & Scaling:
ShouldQueue and Cache\Store align with Laravel’s latest patterns.HttpKernel) for HTTP and kernel-related contracts, ensuring compatibility with Symfony-based Laravel extensions.dragon-code/helpers (e.g., Dtoable for serialization) if adopted.rememberForever for cache). Use adapter patterns for non-Laravel PHP projects.| Phase | Action Items | Dependencies | Risks |
|---|---|---|---|
| Assessment | Audit existing code for caching, queues, DTOs, and HTTP clients to identify high-impact areas for contract adoption. | None | Underestimating refactoring effort for legacy code. |
| Pilot Project | Select a new module or feature (e.g., a microservice) to fully adopt contracts (e.g., Dtoable for API responses, ShouldQueue for jobs). |
Composer, PHP 8.3+, Laravel 11/12 | Scope creep if pilot becomes too broad. |
| Core Contracts | Implement critical contracts in shared libraries first: | ||
- Dtoable for API/DTO layers |
dragon-code/helpers (optional) |
Breaking changes if DTOs are tightly coupled to existing logic. | |
- Cache\Store and Queue\ShouldQueue for background jobs and caching |
Laravel Cache/Queue systems | Performance regression if contracts introduce overhead. | |
- Http\Builder for HTTP clients |
Symfony HttpKernel or Laravel HTTP client | Incompatibility with custom HTTP implementations. | |
| Gradual Rollout | Retrofit contracts to existing classes in phases: | ||
1. DTOs: Convert data transfer objects to implements Dtoable. |
Serialization issues if dragon-code/helpers is missing. |
||
2. Jobs: Add ShouldQueue/ShouldBeUnique to queueable classes. |
Laravel Queue system | Job deduplication conflicts if ShouldBeUnique is misapplied. |
|
3. Cache: Replace custom cache interfaces with Cache\Store. |
Laravel Cache |
How can I help you explore Laravel packages today?