mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FIX Static polution with informational fields
This commit is contained in:
parent
7f58730904
commit
e6352dffbb
@ -63,7 +63,7 @@ class SS_ConfigStaticManifest {
|
|||||||
if (isset($this->index[$class])) {
|
if (isset($this->index[$class])) {
|
||||||
$info = $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;
|
$this->statics += $details;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +95,7 @@ class SS_ConfigStaticManifest {
|
|||||||
* Completely regenerates the manifest file.
|
* Completely regenerates the manifest file.
|
||||||
*/
|
*/
|
||||||
public function regenerate($cache = true) {
|
public function regenerate($cache = true) {
|
||||||
|
$this->index = array('$statics' => array());
|
||||||
$this->statics = array();
|
$this->statics = array();
|
||||||
|
|
||||||
$finder = new ManifestFileFinder();
|
$finder = new ManifestFileFinder();
|
||||||
@ -108,22 +109,17 @@ class SS_ConfigStaticManifest {
|
|||||||
$finder->find($this->base);
|
$finder->find($this->base);
|
||||||
|
|
||||||
if($cache) {
|
if($cache) {
|
||||||
$index = array('$statics' => array());
|
|
||||||
$keysets = array();
|
$keysets = array();
|
||||||
|
|
||||||
foreach ($this->statics as $class => $details) {
|
foreach ($this->statics as $class => $details) {
|
||||||
if (in_array($class, self::$initial_classes)) {
|
if (in_array($class, self::$initial_classes)) {
|
||||||
$index['$statics'][$class] = $details;
|
$this->index['$statics'][$class] = $details;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$key = sha1($class);
|
$key = sha1($class);
|
||||||
$keysets[$key][$class] = $details;
|
$this->index[$class]['key'] = $key;
|
||||||
|
|
||||||
$index[$class] = array(
|
$keysets[$key][$class] = $details;
|
||||||
'key' => $key,
|
|
||||||
'path' => $details['path'],
|
|
||||||
'mtime' => filemtime($details['path']),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,13 +127,16 @@ class SS_ConfigStaticManifest {
|
|||||||
$this->cache->save($details, $this->key.'_'.$key);
|
$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) {
|
public function handleFile($basename, $pathname, $depth) {
|
||||||
$parser = new SS_ConfigStaticManifest_Parser($pathname);
|
$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() {
|
public function getStatics() {
|
||||||
@ -155,6 +154,7 @@ class SS_ConfigStaticManifest {
|
|||||||
*/
|
*/
|
||||||
class SS_ConfigStaticManifest_Parser {
|
class SS_ConfigStaticManifest_Parser {
|
||||||
|
|
||||||
|
protected $info = array();
|
||||||
protected $statics = array();
|
protected $statics = array();
|
||||||
|
|
||||||
protected $path;
|
protected $path;
|
||||||
@ -171,6 +171,14 @@ class SS_ConfigStaticManifest_Parser {
|
|||||||
$this->pos = 0;
|
$this->pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getInfo() {
|
||||||
|
return $this->info;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatics() {
|
||||||
|
return $this->statics;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next token to process, incrementing the pointer
|
* Get the next token to process, incrementing the pointer
|
||||||
*
|
*
|
||||||
@ -198,7 +206,6 @@ class SS_ConfigStaticManifest_Parser {
|
|||||||
|
|
||||||
if($type == T_CLASS) {
|
if($type == T_CLASS) {
|
||||||
$next = $this->next();
|
$next = $this->next();
|
||||||
|
|
||||||
if($next[0] != T_STRING) {
|
if($next[0] != T_STRING) {
|
||||||
user_error("Couldn\'t parse {$this->path} when building config static manifest", E_USER_ERROR);
|
user_error("Couldn\'t parse {$this->path} when building config static manifest", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
@ -233,8 +240,6 @@ class SS_ConfigStaticManifest_Parser {
|
|||||||
$access = '';
|
$access = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->statics;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -299,13 +304,17 @@ class SS_ConfigStaticManifest_Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->statics[$class])) {
|
if (!isset($this->info[$class])) {
|
||||||
$this->statics[$class] = array(
|
$this->info[$class] = array(
|
||||||
'path' => $this->path,
|
'path' => $this->path,
|
||||||
'statics' => array()
|
'mtime' => filemtime($this->path),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!isset($this->statics[$class])) {
|
||||||
|
$this->statics[$class] = array();
|
||||||
|
}
|
||||||
|
|
||||||
$this->statics[$class][$variable] = array(
|
$this->statics[$class][$variable] = array(
|
||||||
'access' => $access,
|
'access' => $access,
|
||||||
'value' => eval('return '.$value.';')
|
'value' => eval('return '.$value.';')
|
||||||
|
@ -51,14 +51,14 @@ class ConfigStaticManifestTest extends SapphireTest {
|
|||||||
|
|
||||||
if ($statics === null) {
|
if ($statics === null) {
|
||||||
$parser = new SS_ConfigStaticManifest_Parser(__FILE__);
|
$parser = new SS_ConfigStaticManifest_Parser(__FILE__);
|
||||||
$statics = $parser->parse();
|
$parser->parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $statics;
|
return $parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParsingAccessLevels() {
|
public function testParsingAccessLevels() {
|
||||||
$statics = $this->parseSelf();
|
$statics = $this->parseSelf()->getStatics();
|
||||||
|
|
||||||
$levels = array(
|
$levels = array(
|
||||||
'nolevel' => null,
|
'nolevel' => null,
|
||||||
@ -80,7 +80,7 @@ class ConfigStaticManifestTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testParsingValues() {
|
public function testParsingValues() {
|
||||||
$statics = $this->parseSelf();
|
$statics = $this->parseSelf()->getStatics();
|
||||||
|
|
||||||
// Check assigning values
|
// Check assigning values
|
||||||
$values = array(
|
$values = array(
|
||||||
@ -112,12 +112,12 @@ class ConfigStaticManifestTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testIgnoresMethodStatics() {
|
public function testIgnoresMethodStatics() {
|
||||||
$statics = $this->parseSelf();
|
$statics = $this->parseSelf()->getStatics();
|
||||||
$this->assertNull(@$statics[__CLASS__]['method_static']);
|
$this->assertNull(@$statics[__CLASS__]['method_static']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIgnoresStaticMethods() {
|
public function testIgnoresStaticMethods() {
|
||||||
$statics = $this->parseSelf();
|
$statics = $this->parseSelf()->getStatics();
|
||||||
$this->assertNull(@$statics[__CLASS__]['static_method']);
|
$this->assertNull(@$statics[__CLASS__]['static_method']);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user