public function shutdownObject()
{
if (count($this->newExpressions) > 0) {
$changesToPersist = false;
$codeToBeCached = $this->expressionCache->get('cachedExpressionClosures');
/**
* At this point a race condition could happen, that we try to prevent with an additional check.
* So we compare the evaluated expressions during this request with the methods the cache has at
* this point and only add methods that are not present. Only if we added anything we write the cache.
*/
foreach ($this->newExpressions as $functionName => $newExpression) {
if (strpos($codeToBeCached, $functionName) === false) {
$codeToBeCached .= 'if (!function_exists(\'' . $functionName . '\')) { ' . $newExpression . ' }' . chr(10);
$changesToPersist = true;
}
}
if ($changesToPersist) {
$this->expressionCache->set('cachedExpressionClosures', $codeToBeCached);
}
}
}