dmp/cg-lib
CG library is a PHP 8.1+ toolset for generating PHP code. It helps assemble and enhance classes by adding reusable behaviors, making it easier to build and modify code structures programmatically during code generation workflows.
Illuminate\Contracts\Container\Bindable or leverage dynamic facades.laravel/framework dependency) may introduce versioning friction if Laravel evolves beyond PHP 8.1’s features (e.g., attributes, enums).bootstrap/cache/).App\Generated\) or runtime class loading.AppServiceProvider::boot().Mockery or abstract factories.| Risk Area | Mitigation Strategy |
|---|---|
| Class Caching | Disable Laravel’s class caching (config/caching.php) or implement a cache invalidation hook. |
| Namespace Pollution | Enforce a strict naming convention (e.g., Vendor\Package\Generated\). |
| PHP Version Drift | Monitor Laravel’s PHP version support and fork the package if needed. |
| Performance Overhead | Benchmark generated code vs. native Laravel solutions (e.g., traits, interfaces). |
| Debugging Complexity | Add source maps or runtime logging to trace generated code execution. |
brick/math, php-di/container) that offer similar functionality with Laravel integration?eval() or create_function() usage.ServiceProvider or Console commands). Requires custom bootstrapping.php artisan make:cg-something) to trigger generation.resources/cg-templates/ and compile to bootstrap/generated/ (excluded from Git).AppServiceProvider:
$this->app->bind('Generated\LoggerDecorator', function ($app) {
return (new CGLib\DecoratorGenerator())->generateFor(\App\Models\User::class);
});
league/proxy-manager).| Laravel Feature | Integration Strategy |
|---|---|
| Service Container | Bind generated classes manually or via register() in AppServiceProvider. |
| Eloquent Models | Use model observers or accessors to trigger generation at runtime. |
| Middleware | Generate middleware classes and register via Kernel.php. |
| Events | Listen for Illuminate\Events\Generated (custom event) to trigger code regeneration. |
| Blade Templates | Compile generated helpers into a Helper facade. |
| Queues/Jobs | Generate job classes dynamically (risky; prefer manual for critical jobs). |
app/Generated/).CGLib\BaseGenerator with Laravel-specific logic.composer.json to avoid breaking changes.CGLib\Generator::setDebugMode(true); // Logs generation steps
| Scenario | Impact | Mitigation |
|---|---|---|
| Generation Error | Broken runtime behavior. | Rollback to last known good version. |
| Namespace Collision | Class not autoloaded. | Use unique prefixes (e.g., App\CG\). |
| PHP Version Incompatibility | Package fails on PHP 8.2+. | Fork and update the package. |
| **Cache In |
How can I help you explore Laravel packages today?