atk4/core
Agile Core is a set of reusable PHP traits for building object-oriented frameworks. Provides containers (parent/child), hooks with priorities, automatic init, dynamic methods, factory by class string, app scope injection, and improved exceptions.
atk4/core leverages PHP traits to provide reusable, composable behavior (e.g., Hooks, Containers, DynamicMethods). This aligns well with Laravel’s service container and dependency injection patterns, enabling fine-grained object composition without inheritance.HookTrait enables pub/sub patterns, complementing Laravel’s events and listeners. Useful for cross-cutting concerns (e.g., logging, auth checks) without bloating service classes.FactoryTrait and DiContainerTrait offer runtime class resolution, similar to Laravel’s app()->make(), but with stricter typing and seed-based initialization. Could replace or augment Laravel’s service container for domain-specific object graphs.Exception class with rich rendering (HTML/CLI) and contextual debugging improves Laravel’s default error handling, especially in APIs or CLI tools.Key Synergies:
atk4/core traits via container aliases or macro methods.TrackableTrait for auditing or HookTrait for lifecycle events.DynamicMethods for runtime UI behavior.DiContainerTrait can coexist with Laravel’s container but may require binding overrides to avoid conflicts (e.g., AppServiceProvider::register()).Exception rendering can be extended via Laravel’s exception handlers (app/Exceptions/Handler.php).ConsoleExceptionRenderer integrates seamlessly with Laravel’s CLI error output.AtkPhpunit traits may need namespace isolation.Potential Friction Points:
Has* traits (e.g., HasFactory). Rename or alias atk4/core traits to avoid conflicts.atk4/core’s InitializerTrait may require explicit sequencing (e.g., booted() hooks).atk4/data (dependent package) is not included; would need separate evaluation for Eloquent/Query Builder compatibility.| Risk Area | Severity | Mitigation |
|---|---|---|
| Trait Overload | Medium | Use interfaces to enforce contracts (e.g., HasHooksInterface). |
| Dependency Injection | High | Test DiContainerTrait vs. Laravel’s container in staging before production. |
| Backward Compatibility | Low | Laravel’s LTS support (PHP 8.1+) aligns with atk4/core’s 5.x/6.x releases. |
| Performance Overhead | Low | Traits add minimal runtime cost; benchmark hook dispatch and dynamic methods. |
| Debugging Complexity | Medium | Leverage Exception’s rich rendering in Laravel Debugbar or custom views. |
Critical Questions for TPM:
atk4/core live in the stack?
use HookTrait as AtkHookTrait)?FactoryTrait?AtkPhpunit traits?FreshTests for isolation?atk4/data/atk4/ui later? (Avoids future refactoring.)| Laravel Component | atk4/core Integration | Compatibility Notes |
|---|---|---|
| Service Container | Replace or extend with DiContainerTrait for domain-specific DI. |
Bind atk4/core container as a secondary resolver in AppServiceProvider. |
| Eloquent Models | Use TrackableTrait for auditing, HookTrait for lifecycle events. |
Extend Model with a base class (e.g., AtkModel) to avoid trait conflicts. |
| Events/Listeners | Replace Laravel events with HookTrait for priority-based execution. |
Create a HookListener bridge to translate between the two systems. |
| Blade Views | Use Exception rendering in custom error pages. |
Override render() in App\Exceptions\Handler. |
| Artisan Commands | Leverage ConsoleExceptionRenderer for CLI debugging. |
Extend Illuminate\Console\Command with AtkCommandTrait. |
| Livewire/Inertia | Use DynamicMethods for runtime UI behavior. |
Compose traits in Livewire components (e.g., class MyComponent extends Component { use DynamicMethods; }). |
| Testing | Use AtkPhpunit traits for test isolation and mocking. |
Configure PHPUnit to load atk4/core test traits alongside Laravel’s. |
atk4/core to composer.json and update autoload.app/Traits/AtkBaseTrait) to house atk4/core traits and resolve conflicts.Event system with HookTrait for a user authentication flow.TrackableTrait to an Eloquent model for soft deletes.atk4/core into critical paths (e.g., domain layer).DiContainerTrait as a fallback resolver for domain objects.// AppServiceProvider.php
$this->app->bind('atk4.container', function () {
return new DiContainer();
});
AtkModel extending Illuminate\Database\Eloquent\Model with TrackableTrait and HookTrait.HookListener to translate between Laravel events and atk4/core hooks.AtkPhpunit traits where beneficial.DynamicMethods in components for runtime UI logic.// app/Http/Livewire/MyComponent.php
use DynamicMethods;
class MyComponent extends Component {
use DynamicMethods;
public function addDynamicMethod() {
$this->addMethod('dynamicAction', function () {
return 'Dynamic behavior!';
});
}
}
ConsoleExceptionRenderer for rich CLI errors.How can I help you explore Laravel packages today?