Saves the PHP source code in the cache.
public set ( string $entryIdentifier, string $sourceCode, array $tags = [], integer $lifetime = null ) : void | ||
$entryIdentifier | string | An identifier used for this cache entry, for example the class name |
$sourceCode | string | PHP source code |
$tags | array | Tags to associate with this cache entry |
$lifetime | integer | Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime. |
Результат | void |
/** * Shutdown the Evaluator and save created expressions overwriting any existing expressions * * @return void */ public function saveRuntimeExpressions() { if ($this->newExpressions === []) { return; } $codeToBeCached = 'return array (' . chr(10); foreach ($this->newExpressions as $name => $function) { $codeToBeCached .= "'" . $name . "' => " . $function . ',' . chr(10); } $codeToBeCached .= ');'; $this->runtimeExpressionsCache->set('Flow_Aop_RuntimeExpressions', $codeToBeCached); }
/** * 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 .= 'if (!function_exists(\'' . $functionName . '\')) { ' . $newExpression . ' }' . chr(10); $changesToPersist = true; } } if ($changesToPersist) { $this->expressionCache->set('cachedExpressionClosures', $codeToBeCached); } } }
/** * Reads the specified class file, appends ORIGINAL_CLASSNAME_SUFFIX to its * class name and stores the result in the proxy classes cache. * * @param string $className Short class name of the class to copy * @param string $pathAndFilename Full path and filename of the original class file * @param string $proxyClassCode The code that makes up the proxy class * @return void * * @throws Exception If the original class filename doesn't match the actual class name inside the file. */ protected function cacheOriginalClassFileAndProxyCode($className, $pathAndFilename, $proxyClassCode) { $classCode = file_get_contents($pathAndFilename); $classCode = $this->stripOpeningPhpTag($classCode); $classNameSuffix = self::ORIGINAL_CLASSNAME_SUFFIX; $classCode = preg_replace_callback('/^([a-z\\s]*?)(final\\s+)?(interface|class)\\s+([a-zA-Z0-9_]+)/m', function ($matches) use($pathAndFilename, $classNameSuffix, $proxyClassCode) { $classNameAccordingToFileName = basename($pathAndFilename, '.php'); if ($matches[4] !== $classNameAccordingToFileName) { throw new Exception('The name of the class "' . $matches[4] . '" is not the same as the filename which is "' . basename($pathAndFilename) . '". Path: ' . $pathAndFilename, 1398356897); } return $matches[1] . $matches[3] . ' ' . $matches[4] . $classNameSuffix; }, $classCode); $classCode = preg_replace('/\\?>[\\n\\s\\r]*$/', '', $classCode); $proxyClassCode .= "\n" . '# PathAndFilename: ' . $pathAndFilename; $this->classesCache->set(str_replace('\\', '_', $className), $classCode . $proxyClassCode); }
/** * Set or updates an entry identified by $name * into the cache. * * @param string $name * @param string $value */ public function set($name, $value) { // we need to strip the first line with the php header as the flow cache adds that again. return $this->flowCache->set($name, substr($value, strpos($value, "\n") + 1)); }