-
I often have situations where I need to be able to configure things extensively. Think of the Scheduler. Think of generating Images. Of course, I can create an extensive piece of code that parses an array, but that will not always cover everything and makes the code quite unreadable. I can also add in strings pointing at (invokable) classes, but that requires me to instantiate the object before hands, I can add in closures, as it is an array. The ProblemWhile the error message says: "Your configuration files are not serializable", config:cache does not actually serialize the code. It uses var_export to print it into a cache/config.php file. This makes any solution to serialize objects pointless. The proposalI propose a use Illuminate\Console\Scheduling\CallbackEvent;
return [
'cron' => [
'enabled' => false,
'configure' => export(
function (CallbackEvent $event) {
$event->hourly();
}
)
]
]; The export helper returns an object that serializes the given variable and implements the to allow the code to function when not cached, we should implement __get __call and and __invoke as well. Not sure if someone would want any setters, but imo this should be immutable. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For all who care: I have made a package out of it. I went with Just install with: https://github.com/henzeb/var-export-wrapper |
Beta Was this translation helpful? Give feedback.
For all who care: I have made a package out of it. I went with
exportify
and an automated version of transforming elements in the config array when callingconfig:cache
, which is much cleaner. I also did not add the resolve feature, as I wanted the package to be useful outside laravel installations.Just install with: https://github.com/henzeb/var-export-wrapper