-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Config caching causes a problem when having closure #24103
Comments
You can't cache closures. |
This is possible @tillkruss using SuperClosure, we will serialize it first and the 'C:32:"SuperClosure\\SerializableClosure":388:{a:5:{s:4:"code";s:253:"function () {
return [\'email\' => \'[email protected]\', \'fullName\' => \'John Doe\', \'forgotPasswordToken\' => \'qwertyuiopasdfghjklzxcvbnm\', \'link\' => \\route(\'auth.reset-password.update-get\', [\'forgot_password_token\' => \'qwertyuiopasdfghjklzxcvbnm\'])];
}";s:7:"context";a:0:{}s:7:"binding";N;s:5:"scope";s:34:"Illuminate\\Support\\ServiceProvider";s:8:"isStatic";b:0;}}' At /**
* Serialize the records.
*
* @param array $records
* @return array
*/
protected function transformClosure(array $records)
{
$serializer = new Serializer;
foreach ($records as $key => $val) {
if (is_array($val)) {
$records[$key] = $this->transformClosure($val);
}
if ($val instanceof \Closure) {
$records[$key] = $serializer->serialize($val);
}
}
return $records;
} At /**
* Value analyzer and changer.
*
* @param mixed $value
* @return mixed
*/
public function realValue($value)
{
if (
is_string($value) &&
strpos($value, "SuperClosure\\SerializableClosure") !== false
) {
return (new \SuperClosure\Serializer())->unserialize($value);
}
return $value;
} ProofIf you think this is okay, will apply a PR instead. |
Yeah, please feel free to submit a PR. |
Description:
When running
config:cache
this thing caches inside your bootstrap/cache/config.php, but I have some closures inside my config, see. Steps To Produce.After the caching, if you will try to run the
artisan
command again. It will throw now an error nowClass config does not exist in {path to Illuminate/Container/Container.php}
I tried to manually removing
Closure::__set_state(array())
inside the cached config and artisan works, but my closure config does not exists now, actually the data of the closure was not able to capture.Steps To Reproduce:
Edit 1
If we're strict to use raw config, why can't we use serialize first to prevent using Closures/Objects, only
var_export()
directly insideConfigCacheCommand.php
. I would like to suggest, maybe to usejeremeamia/super_closure
package to support this kind of scenario.The text was updated successfully, but these errors were encountered: