From ba6bd4b221e082c2d2864564c23617ad713d10a5 Mon Sep 17 00:00:00 2001 From: alexandresalome Date: Sun, 9 Oct 2011 22:45:55 +0200 Subject: [PATCH] [HttpKernel] Fix the FileProfileStorage, according to the tests --- .../Profiler/FileProfilerStorage.php | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php index ef14035d25..3c97e6e837 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php @@ -122,7 +122,17 @@ class FileProfilerStorage implements ProfilerStorageInterface return null; } - return unserialize(file_get_contents($file)); + $profile = unserialize(file_get_contents($file)); + + $childrenFile = $this->getChildrenFilename($token); + if (file_exists($childrenFile)) { + $childrenTokens = explode(',', file_get_contents($childrenFile)); + foreach ($childrenTokens as $childToken) { + $profile->addChild($this->read($childToken)); + } + } + + return $profile; } /** @@ -153,6 +163,14 @@ class FileProfilerStorage implements ProfilerStorageInterface )); fclose($file); + if ($profile->getParent()) { + $childrenFile = $this->getChildrenFilename($profile->getParent()->getToken()); + $toWrite = file_exists($childrenFile) ? ','.$profile->getToken() : $profile->getToken(); + $fp = fopen($childrenFile, 'a'); + fputs($fp, $toWrite); + fclose($fp); + } + return ! $exists; } @@ -170,6 +188,16 @@ class FileProfilerStorage implements ProfilerStorageInterface return $this->folder.'/'.$folderA.'/'.$folderB.'/'.$token; } + /** + * Gets filename to store children tokens. + * + * @return string The tokens filename + */ + protected function getChildrenFilename($token) + { + return $this->getFilename($token).'.children'; + } + /** * Gets the index filename. *