/** * Shutdown the Evaluator */ 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 .= $newExpression . chr(10); $changesToPersist = TRUE; } } if ($changesToPersist) { $this->expressionCache->set('cachedExpressionClosures', $codeToBeCached); } } }