Cannot cache laravel config using your enums
torian257x opened this issue · comments
myconfig.php
return [
'mysetting' => SomeEnumType::myFoo(),
];
when running php artisan config:cache
gives
LogicException
Your configuration files are not serializable.
at vendor/laravel/framework/src/Illuminate/Foundation/Console/ConfigCacheCommand.php:71
67▕ require $configPath;
68▕ } catch (Throwable $e) {
69▕ $this->files->delete($configPath);
70▕
➜ 71▕ throw new LogicException('Your configuration files are not serializable.', 0, $e);
72▕ }
73▕
74▕ $this->info('Configuration cached successfully!');
75▕ }
+2 vendor frames
3 bootstrap/cache/config.php:797
BenSampo\Enum\Enum::__callStatic()
+14 vendor frames
18 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
What method does Laravel use to serialize the config?
looks like config:cache uses var_export
look here Illuminate\Foundation\Console
ConfigCacheCommand.php
I think we just need to implement __set_state()
, see https://www.php.net/manual/en/language.oop5.magic.php#object.set-state