Merge pull request #6666 from open-sausages/pulls/4.0/soft-autoload

BUG Prevent obsolete class cache breaking autoload
This commit is contained in:
Ingo Schommer 2017-03-01 12:09:17 +13:00 committed by GitHub
commit 1f3f645106
3 changed files with 12 additions and 25 deletions

View File

@ -206,12 +206,14 @@ class ClassManifest
{ {
$name = strtolower($name); $name = strtolower($name);
if (isset($this->classes[$name])) { foreach ([
return $this->classes[$name]; $this->classes,
} elseif (isset($this->interfaces[$name])) { $this->interfaces,
return $this->interfaces[$name]; $this->traits
} elseif (isset($this->traits[$name])) { ] as $source) {
return $this->traits[$name]; if (isset($source[$name]) && file_exists($source[$name])) {
return $source[$name];
}
} }
return null; return null;
} }
@ -381,15 +383,6 @@ class ClassManifest
return array_shift($parts); return array_shift($parts);
} }
/**
* Used to set up files that we want to exclude from parsing for performance reasons.
*/
protected function setDefaults()
{
$this->classes['sstemplateparser'] = FRAMEWORK_PATH.'/src/View/SSTemplateParser.php';
$this->classes['sstemplateparseexception'] = FRAMEWORK_PATH.'/src/View/SSTemplateParseException.php';
}
/** /**
* Completely regenerates the manifest file. * Completely regenerates the manifest file.
* *
@ -407,12 +400,10 @@ class ClassManifest
$this->$reset = array(); $this->$reset = array();
} }
$this->setDefaults();
$finder = new ManifestFileFinder(); $finder = new ManifestFileFinder();
$finder->setOptions(array( $finder->setOptions(array(
'name_regex' => '/^(_config.php|[^_].*\.php)$/', 'name_regex' => '/^((_config)|([^_].*))\\.php$/',
'ignore_files' => array('index.php', 'main.php', 'cli-script.php', 'SSTemplateParser.php'), 'ignore_files' => array('index.php', 'main.php', 'cli-script.php'),
'ignore_tests' => !$this->tests, 'ignore_tests' => !$this->tests,
'file_callback' => array($this, 'handleFile'), 'file_callback' => array($this, 'handleFile'),
'dir_callback' => array($this, 'handleDir') 'dir_callback' => array($this, 'handleDir')

View File

@ -50,8 +50,6 @@ class ClassManifestTest extends SapphireTest
'classc' => "{$this->base}/module/classes/ClassC.php", 'classc' => "{$this->base}/module/classes/ClassC.php",
'classd' => "{$this->base}/module/classes/ClassD.php", 'classd' => "{$this->base}/module/classes/ClassD.php",
'classe' => "{$this->base}/module/classes/ClassE.php", 'classe' => "{$this->base}/module/classes/ClassE.php",
'sstemplateparser' => FRAMEWORK_PATH."/src/View/SSTemplateParser.php",
'sstemplateparseexception' => FRAMEWORK_PATH."/src/View/SSTemplateParseException.php"
); );
$this->assertEquals($expect, $this->manifest->getClasses()); $this->assertEquals($expect, $this->manifest->getClasses());
} }
@ -59,7 +57,7 @@ class ClassManifestTest extends SapphireTest
public function testGetClassNames() public function testGetClassNames()
{ {
$this->assertEquals( $this->assertEquals(
array('sstemplateparser', 'sstemplateparseexception', 'classa', 'classb', 'classc', 'classd', 'classe'), ['classa', 'classb', 'classc', 'classd', 'classe'],
$this->manifest->getClassNames() $this->manifest->getClassNames()
); );
} }

View File

@ -263,8 +263,6 @@ class NamespacedClassManifestTest extends SapphireTest
'silverstripe\test\classf' => "{$this->base}/module/classes/ClassF.php", 'silverstripe\test\classf' => "{$this->base}/module/classes/ClassF.php",
'silverstripe\test\classg' => "{$this->base}/module/classes/ClassG.php", 'silverstripe\test\classg' => "{$this->base}/module/classes/ClassG.php",
'silverstripe\test\classh' => "{$this->base}/module/classes/ClassH.php", 'silverstripe\test\classh' => "{$this->base}/module/classes/ClassH.php",
'sstemplateparser' => FRAMEWORK_PATH."/src/View/SSTemplateParser.php",
'sstemplateparseexception' => FRAMEWORK_PATH."/src/View/SSTemplateParseException.php",
'silverstripe\framework\tests\classi' => "{$this->base}/module/classes/ClassI.php", 'silverstripe\framework\tests\classi' => "{$this->base}/module/classes/ClassI.php",
); );
@ -274,7 +272,7 @@ class NamespacedClassManifestTest extends SapphireTest
public function testGetClassNames() public function testGetClassNames()
{ {
$this->assertEquals( $this->assertEquals(
array('sstemplateparser', 'sstemplateparseexception', 'silverstripe\test\classa', array('silverstripe\test\classa',
'silverstripe\test\classb', 'silverstripe\test\classc', 'silverstripe\test\classd', 'silverstripe\test\classb', 'silverstripe\test\classc', 'silverstripe\test\classd',
'silverstripe\test\classe', 'silverstripe\test\classf', 'silverstripe\test\classg', 'silverstripe\test\classe', 'silverstripe\test\classf', 'silverstripe\test\classg',
'silverstripe\test\classh', 'silverstripe\framework\tests\classi'), 'silverstripe\test\classh', 'silverstripe\framework\tests\classi'),