From 7927fffc0a65962290fdb22e3c4a530e41a0a040 Mon Sep 17 00:00:00 2001 From: Dominik Beerbohm Date: Sat, 3 Mar 2012 15:10:09 +0100 Subject: [PATCH 1/2] AP(RE)CHANGE Exclude files with the underscore prefix from manifest. --- core/manifest/ClassManifest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/manifest/ClassManifest.php b/core/manifest/ClassManifest.php index 5bbe0c3bb..ddc99c703 100644 --- a/core/manifest/ClassManifest.php +++ b/core/manifest/ClassManifest.php @@ -276,7 +276,7 @@ class SS_ClassManifest { $finder = new ManifestFileFinder(); $finder->setOptions(array( - 'name_regex' => '/\.php$/', + 'name_regex' => '/^[^_].*\.php$/', 'ignore_files' => array('index.php', 'main.php', 'cli-script.php'), 'ignore_tests' => !$this->tests, 'file_callback' => array($this, 'handleFile') From 42f8d9f77a6e13c2b0513d837e1e9a92261bf642 Mon Sep 17 00:00:00 2001 From: AngryPHPNerd Date: Tue, 13 Mar 2012 23:38:34 +0100 Subject: [PATCH 2/2] - Readded check for _config.php in ClassManifest. - Added UnitTest for files with underscore prefix. --- core/manifest/ClassManifest.php | 28 +++++++++---------- tests/core/manifest/ClassManifestTest.php | 5 +++- .../classmanifest/module/classes/_Ignore.php | 5 ++++ 3 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 tests/core/manifest/fixtures/classmanifest/module/classes/_Ignore.php diff --git a/core/manifest/ClassManifest.php b/core/manifest/ClassManifest.php index ddc99c703..60c51cf6b 100644 --- a/core/manifest/ClassManifest.php +++ b/core/manifest/ClassManifest.php @@ -52,7 +52,7 @@ class SS_ClassManifest { 15 => '{', )); } - + /** * @return TokenisedRegularExpression */ @@ -78,7 +78,7 @@ class SS_ClassManifest { 17 => '{', )); } - + /** * @return TokenisedRegularExpression */ @@ -92,7 +92,7 @@ class SS_ClassManifest { 5 => ';', )); } - + /** * @return TokenisedRegularExpression */ @@ -103,7 +103,7 @@ class SS_ClassManifest { 2 => array(T_STRING, 'save_to' => 'interfaceName') )); } - + /** * Constructs and initialises a new class manifest, either loading the data * from the cache or re-scanning for classes. @@ -243,11 +243,11 @@ class SS_ClassManifest { public function getConfigs() { return $this->configs; } - + /** * Returns an array of module names mapped to their paths. * "Modules" in sapphire are simply directories with a _config.php file. - * + * * @return array */ public function getModules() { @@ -268,7 +268,7 @@ class SS_ClassManifest { 'classes', 'roots', 'children', 'descendants', 'interfaces', 'implementors', 'configs' ); - + // Reset the manifest so stale info doesn't cause errors. foreach ($reset as $reset) { $this->$reset = array(); @@ -276,7 +276,7 @@ class SS_ClassManifest { $finder = new ManifestFileFinder(); $finder->setOptions(array( - 'name_regex' => '/^[^_].*\.php$/', + 'name_regex' => '/^(_config.php|[^_].*\.php)$/', 'ignore_files' => array('index.php', 'main.php', 'cli-script.php'), 'ignore_tests' => !$this->tests, 'file_callback' => array($this, 'handleFile') @@ -328,7 +328,7 @@ class SS_ClassManifest { $namespace = $data['namespace']; } } - + if (!$classes) { $tokens = token_get_all($file); if(version_compare(PHP_VERSION, '5.3', '>=')) { @@ -353,7 +353,7 @@ class SS_ClassManifest { $name = $namespace . $class['className']; $extends = isset($class['extends']) ? implode('', $class['extends']) : null; $implements = isset($class['interfaces']) ? $class['interfaces'] : null; - + if($extends && $extends[0] != '\\') { $extends = $namespace . $extends; } elseif($extends) { @@ -380,7 +380,7 @@ class SS_ClassManifest { } else { $this->roots[] = $name; } - + if ($implements) { $interface = $namespace; for($i = 0; $i < count($implements); ++$i) { @@ -395,7 +395,7 @@ class SS_ClassManifest { } if($i == count($implements)-1 || $implements[$i+1] == ',') { $interface = strtolower($interface); - + if (!isset($this->implementors[$interface])) { $this->implementors[$interface] = array($name); } else { @@ -405,7 +405,7 @@ class SS_ClassManifest { } } } - + foreach ($interfaces as $interface) { $this->interfaces[strtolower($namespace . $interface['interfaceName'])] = $pathname; } @@ -421,7 +421,7 @@ class SS_ClassManifest { protected function coalesceDescendants($class) { $result = array(); $lClass = strtolower($class); - + if (array_key_exists($lClass, $this->children)) { $this->descendants[$lClass] = array(); diff --git a/tests/core/manifest/ClassManifestTest.php b/tests/core/manifest/ClassManifestTest.php index 6fa4fe836..900021a80 100644 --- a/tests/core/manifest/ClassManifestTest.php +++ b/tests/core/manifest/ClassManifestTest.php @@ -105,7 +105,7 @@ class ClassManifestTest extends SapphireTest { $this->assertEquals($expect, $this->manifest->getConfigs()); $this->assertEquals($expect, $this->manifestTests->getConfigs()); } - + public function testGetModules() { $expect = array("module" => "{$this->base}/module"); $this->assertEquals($expect, $this->manifest->getModules()); @@ -117,4 +117,7 @@ class ClassManifestTest extends SapphireTest { $this->assertContains('testclassa', array_keys($this->manifestTests->getClasses())); } + public function testManifestExcludeFilesPrefixedWithUnderscore() { + $this->assertNotContains('ignore', array_keys($this->manifest->getClasses())); + } } \ No newline at end of file diff --git a/tests/core/manifest/fixtures/classmanifest/module/classes/_Ignore.php b/tests/core/manifest/fixtures/classmanifest/module/classes/_Ignore.php new file mode 100644 index 000000000..2751fa590 --- /dev/null +++ b/tests/core/manifest/fixtures/classmanifest/module/classes/_Ignore.php @@ -0,0 +1,5 @@ +