l0n3ly/laravel-dynamic-helpers
Pros:
Store/ProductHelper), improving organization for large applications..phpstorm.meta.php and _ide_helper.php for autocompletion and type hints, enhancing developer experience.Cons:
eval() usage: Generates PHP functions at runtime via eval(), which may raise security concerns in shared environments or strict code review policies.__call, __callStatic): While flexible, they can obscure intent and make debugging harder.eval() usage could be flagged in security audits or CI pipelines (e.g., PHPStan, Psalm). Mitigation: Document the trade-off and restrict usage to trusted environments..phpstorm.meta.php) may clutter the project or cause merge conflicts. Mitigation: Exclude from version control (handled via .gitignore).Security:
eval() acceptable for your team’s security policies? If not, can the package be modified to use alternative approaches (e.g., pre-compiled helper files)?Testing:
helpers() facade or using static calls where possible.Maintenance:
@deprecated annotation system.Scalability:
IDE/Tooling:
.phpstorm.meta.php generation works in your CI/CD pipeline.Assessment Phase:
Pilot Migration:
StringHelper to app/Helpers/StringHelper.php and replace str_helper() with stringHelper().Incremental Adoption:
php artisan make:helper.moneyHelper()->format()).@if(permissionHelper()->can())).HelperProxy if needed).use App\Helpers\MoneyHelper) for static access if preferred.Nested Helpers:
Store/ProductHelper, Auth/RoleHelper).storeProductHelper()).Deprecation:
DeprecatesOld trait).if (class_exists(\App\Helpers\MoneyHelper::class)) {
return moneyHelper()->format($amount);
}
return old_money_format($amount); // Deprecated global function
helper()) remain unchanged but can be replaced with dynamic alternatives.Helper::method()) can coexist via __callStatic magic methods.Helper::run()) may need adjustments to use the HelperProxy.str(), arr()).helpers()->original() to access Laravel’s built-in helpers if needed.Installation:
composer require l0n3ly/laravel-dynamic-helpers
Generate Helpers:
php artisan make:helper MoneyHelper
php artisan make:helper Store/ProductHelper
Update Codebase:
global_helper() with helperNameHelper().use App\Helpers\MoneyHelper).Test:
php artisan tinker to measure startup time).Deploy:
Optimize:
.gitignore).app/Helpers, making them easier to locate and maintain.StoreHelper → storeHelper()) enforces conventions..phpstorm.meta.php) need occasional cleanup or exclusion from version control.php artisan make:helper.app/Helpers directory exists and is readable.tideways/xhprof or Laravel Debugbar.helpers()->flush() to clear the helper cache (if needed).boot() method for dynamic registration logic.How can I help you explore Laravel packages today?