From e6352dffbbf8a6deb3f4fc319b1778c4348b303d Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Tue, 12 Mar 2013 17:14:12 +1300 Subject: [PATCH] FIX Static polution with informational fields --- core/manifest/ConfigStaticManifest.php | 43 +++++++++++-------- .../manifest/ConfigStaticManifestTest.php | 12 +++--- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/core/manifest/ConfigStaticManifest.php b/core/manifest/ConfigStaticManifest.php index ee73da5e0..486871e10 100644 --- a/core/manifest/ConfigStaticManifest.php +++ b/core/manifest/ConfigStaticManifest.php @@ -63,7 +63,7 @@ class SS_ConfigStaticManifest { if (isset($this->index[$class])) { $info = $this->index[$class]; - if ($details = $this->cache->load($this->key.'_'.$info['key'])) { + if (isset($info['key']) && $details = $this->cache->load($this->key.'_'.$info['key'])) { $this->statics += $details; } @@ -95,6 +95,7 @@ class SS_ConfigStaticManifest { * Completely regenerates the manifest file. */ public function regenerate($cache = true) { + $this->index = array('$statics' => array()); $this->statics = array(); $finder = new ManifestFileFinder(); @@ -108,22 +109,17 @@ class SS_ConfigStaticManifest { $finder->find($this->base); if($cache) { - $index = array('$statics' => array()); $keysets = array(); foreach ($this->statics as $class => $details) { if (in_array($class, self::$initial_classes)) { - $index['$statics'][$class] = $details; + $this->index['$statics'][$class] = $details; } else { $key = sha1($class); - $keysets[$key][$class] = $details; + $this->index[$class]['key'] = $key; - $index[$class] = array( - 'key' => $key, - 'path' => $details['path'], - 'mtime' => filemtime($details['path']), - ); + $keysets[$key][$class] = $details; } } @@ -131,13 +127,16 @@ class SS_ConfigStaticManifest { $this->cache->save($details, $this->key.'_'.$key); } - $this->cache->save($index, $this->key); + $this->cache->save($this->index, $this->key); } } public function handleFile($basename, $pathname, $depth) { $parser = new SS_ConfigStaticManifest_Parser($pathname); - $this->statics = array_merge($this->statics, $parser->parse()); + $parser->parse(); + + $this->index = array_merge($this->index, $parser->getInfo()); + $this->statics = array_merge($this->statics, $parser->getStatics()); } public function getStatics() { @@ -155,6 +154,7 @@ class SS_ConfigStaticManifest { */ class SS_ConfigStaticManifest_Parser { + protected $info = array(); protected $statics = array(); protected $path; @@ -171,6 +171,14 @@ class SS_ConfigStaticManifest_Parser { $this->pos = 0; } + function getInfo() { + return $this->info; + } + + function getStatics() { + return $this->statics; + } + /** * Get the next token to process, incrementing the pointer * @@ -198,7 +206,6 @@ class SS_ConfigStaticManifest_Parser { if($type == T_CLASS) { $next = $this->next(); - if($next[0] != T_STRING) { user_error("Couldn\'t parse {$this->path} when building config static manifest", E_USER_ERROR); } @@ -233,8 +240,6 @@ class SS_ConfigStaticManifest_Parser { $access = ''; } } - - return $this->statics; } /** @@ -299,13 +304,17 @@ class SS_ConfigStaticManifest_Parser { } } - if(!isset($this->statics[$class])) { - $this->statics[$class] = array( + if (!isset($this->info[$class])) { + $this->info[$class] = array( 'path' => $this->path, - 'statics' => array() + 'mtime' => filemtime($this->path), ); } + if(!isset($this->statics[$class])) { + $this->statics[$class] = array(); + } + $this->statics[$class][$variable] = array( 'access' => $access, 'value' => eval('return '.$value.';') diff --git a/tests/core/manifest/ConfigStaticManifestTest.php b/tests/core/manifest/ConfigStaticManifestTest.php index fa8c49210..ceaa13da1 100644 --- a/tests/core/manifest/ConfigStaticManifestTest.php +++ b/tests/core/manifest/ConfigStaticManifestTest.php @@ -51,14 +51,14 @@ class ConfigStaticManifestTest extends SapphireTest { if ($statics === null) { $parser = new SS_ConfigStaticManifest_Parser(__FILE__); - $statics = $parser->parse(); + $parser->parse(); } - return $statics; + return $parser; } public function testParsingAccessLevels() { - $statics = $this->parseSelf(); + $statics = $this->parseSelf()->getStatics(); $levels = array( 'nolevel' => null, @@ -80,7 +80,7 @@ class ConfigStaticManifestTest extends SapphireTest { } public function testParsingValues() { - $statics = $this->parseSelf(); + $statics = $this->parseSelf()->getStatics(); // Check assigning values $values = array( @@ -112,12 +112,12 @@ class ConfigStaticManifestTest extends SapphireTest { } public function testIgnoresMethodStatics() { - $statics = $this->parseSelf(); + $statics = $this->parseSelf()->getStatics(); $this->assertNull(@$statics[__CLASS__]['method_static']); } public function testIgnoresStaticMethods() { - $statics = $this->parseSelf(); + $statics = $this->parseSelf()->getStatics(); $this->assertNull(@$statics[__CLASS__]['static_method']); } } \ No newline at end of file