fbca330879274530475d338291d4e68d8cbc179e
Author: Mark Story
Date: 2009-02-05 22:38:15 -0500
diff --git a/models/api_class.php b/models/api_class.php
index 4e5ffbf..2ae6203 100644
--- a/models/api_class.php
+++ b/models/api_class.php
@@ -239,6 +239,19 @@ class ApiClass extends ApiGeneratorAppModel {
$_return[$relevance][$name]['class'][$name] = $obj;
}
}
+ foreach ($result['function'] as $name => $obj) {
+ $relevance = 0;
+ foreach ($terms as $term) {
+ if (low($name) === $term) {
+ $relevance += 6;
+ } elseif (strpos(low($name), $term) === 0) {
+ $relevance += 3;
+ }
+ if ($relevance > 0) {
+ $_return[$relevance][$name]['function'][$name] = $obj;
+ }
+ }
+ }
}
ksort($_return);
$_return = array_reverse($_return);
diff --git a/models/api_file.php b/models/api_file.php
index 7a4150a..290be10 100644
--- a/models/api_file.php
+++ b/models/api_file.php
@@ -259,6 +259,9 @@ class ApiFile extends Object {
foreach ($newObjects as $type => $objects) {
foreach ($objects as $element) {
$this->loadExtractor($type, $element);
+ if ($type == 'function' && basename($this->_extractor->getFileName()) != basename($filePath)) {
+ continue;
+ }
$docs[$type][$element] = $this->getDocs();
}
}
@@ -291,10 +294,11 @@ class ApiFile extends Object {
* @param boolean $forceParse Force the manual read of a file.
* @return array
**/
- public function findObjectsInFile($filePath, $forceParse = false) {
+ public function findObjectsInFile($filePath) {
$new = $tmp = array();
$tmp['class'] = $this->_parseClassNamesInFile($filePath);
$tmp['function'] = $this->_parseFunctionNamesInFile($filePath);
+
$include = false;
foreach ($tmp['class'] as $classInFile) {
$include = false;
@@ -302,7 +306,13 @@ class ApiFile extends Object {
$include = true;
}
}
- if (!$include || $forceParse) {
+ foreach ($tmp['function'] as $funcInFile) {
+ if (!function_exists($funcInFile)) {
+ $include = true;
+ }
+ }
+
+ if (!$include) {
$new = $tmp;
} else {
ob_start();
@@ -313,9 +323,6 @@ class ApiFile extends Object {
$funcs = get_defined_functions();
$new['function'] = array_diff($funcs['user'], $this->_definedFunctions);
}
- if (empty($new['class']) && empty($new['function']) && $forceParse === false) {
- $new = $this->findObjectsInFile($filePath, true);
- }
return $new;
}
/**
@@ -356,7 +363,7 @@ class ApiFile extends Object {
$foundFuncs = array();
$fileContent = file_get_contents($fileName);
$funcNames = implode('|', $this->_definedFunctions);
- preg_match_all('/^\s*function\s*(' . $funcNames . ')[\s|\(]+/mi', $fileContent, $matches, PREG_SET_ORDER);
+ preg_match_all('/^\tfunction\s*(' . $funcNames . ')[\s|\(]+/mi', $fileContent, $matches, PREG_SET_ORDER);
foreach ($matches as $function) {
$foundFuncs[] = $function[1];
}
diff --git a/tests/cases/models/api_file.test.php b/tests/cases/models/api_file.test.php
index 871862e..953bfc4 100644
--- a/tests/cases/models/api_file.test.php
+++ b/tests/cases/models/api_file.test.php
@@ -232,4 +232,15 @@ class ApiFileTestCase extends CakeTestCase {
$this->assertTrue(true);
}
}
+/**
+ * Test Loading files, that have method config() and having global config() from core included
+ *
+ * @return void
+ **/
+ function testLoadingFileWithAmbiguousFunction() {
+ $cacheFile = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'cache.php';
+ $this->assertTrue(function_exists('config'));
+ $results = $this->ApiFile->loadFile($cacheFile);
+ $this->assertEqual($results['function'], array());
+ }
}
\ No newline at end of file
