Permalink
Browse files

FIX Static polution with informational fields

  • Loading branch information...
1 parent 7f58730 commit e6352dffbbf8a6deb3f4fc319b1778c4348b303d Hamish Friedlander committed Mar 12, 2013
Showing with 32 additions and 23 deletions.
  1. +26 −17 core/manifest/ConfigStaticManifest.php
  2. +6 −6 tests/core/manifest/ConfigStaticManifestTest.php
@@ -63,7 +63,7 @@ public function get($class, $name, $default) {
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 @@ public function get($class, $name, $default) {
* Completely regenerates the manifest file.
*/
public function regenerate($cache = true) {
+ $this->index = array('$statics' => array());
$this->statics = array();
$finder = new ManifestFileFinder();
@@ -108,36 +109,34 @@ public function regenerate($cache = true) {
$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;
}
}
foreach ($keysets as $key => $details) {
$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 @@ public function getStatics() {
*/
class SS_ConfigStaticManifest_Parser {
+ protected $info = array();
protected $statics = array();
protected $path;
@@ -171,6 +171,14 @@ function __construct($path) {
$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 @@ function parse() {
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 @@ function parse() {
$access = '';
}
}
-
- return $this->statics;
}
/**
@@ -299,13 +304,17 @@ function parseStatic($access, $class) {
}
}
- 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.';')
@@ -51,14 +51,14 @@ protected function parseSelf() {
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 @@ public function testParsingAccessLevels() {
}
public function testParsingValues() {
- $statics = $this->parseSelf();
+ $statics = $this->parseSelf()->getStatics();
// Check assigning values
$values = array(
@@ -112,12 +112,12 @@ public function testParsingValues() {
}
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']);
}
}

0 comments on commit e6352df

Please sign in to comment.