MINOR: Updated various methods to use new manifest methods rather than ManifestBuilder functions or globals.

This commit is contained in:
ajshort 2011-03-22 20:47:55 +11:00
parent 0c78935db4
commit bc0a1b7a05
6 changed files with 32 additions and 58 deletions

View File

@ -12,16 +12,14 @@ class ClassInfo {
* @todo Improve documentation * @todo Improve documentation
*/ */
static function allClasses() { static function allClasses() {
global $_CLASS_MANIFEST; return SS_ClassLoader::instance()->allClasses();
return ArrayLib::valuekey(array_keys($_CLASS_MANIFEST));
} }
/** /**
* @todo Improve documentation * @todo Improve documentation
*/ */
static function exists($class) { static function exists($class) {
global $_CLASS_MANIFEST; return SS_ClassLoader::instance()->classExists($class);
return class_exists($class, false) || array_key_exists(strtolower($class), $_CLASS_MANIFEST);
} }
/** /**
@ -126,32 +124,16 @@ class ClassInfo {
* @return array Names of all subclasses as an associative array. * @return array Names of all subclasses as an associative array.
*/ */
public static function subclassesFor($class) { public static function subclassesFor($class) {
global $_ALL_CLASSES; $descendants = SS_ClassLoader::instance()->getManifest()->getDescendantsOf($class);
$result = array($class => $class);
if (is_object($class)) { if ($descendants) {
$class = get_class($class); return $result + ArrayLib::valuekey($descendants);
} else {
return $result;
} }
$parents = array($class);
$classes = array($class => $class);
if (!isset($_ALL_CLASSES['children'][$class])) {
return $classes;
}
while ($parent = array_shift($parents)) {
foreach ($_ALL_CLASSES['children'][$parent] as $class) {
$classes[$class] = $class;
if (isset($_ALL_CLASSES['children'][$class])) {
$parents[] = $class;
}
}
}
return $classes;
} }
/** /**
* Returns the passed class name along with all its parent class names in an * Returns the passed class name along with all its parent class names in an
* array, sorted with the root class first. * array, sorted with the root class first.
@ -185,16 +167,14 @@ class ClassInfo {
* classes and not built-in PHP classes. * classes and not built-in PHP classes.
*/ */
static function implementorsOf($interfaceName) { static function implementorsOf($interfaceName) {
global $_ALL_CLASSES; return SS_ClassLoader::instance()->getManifest()->getImplementorsOf($interfaceName);
return (isset($_ALL_CLASSES['implementors'][$interfaceName])) ? $_ALL_CLASSES['implementors'][$interfaceName] : false;
} }
/** /**
* Returns true if the given class implements the given interface * Returns true if the given class implements the given interface
*/ */
static function classImplements($className, $interfaceName) { static function classImplements($className, $interfaceName) {
global $_ALL_CLASSES; return in_array($className, SS_ClassLoader::instance()->getManifest()->getImplementorsOf($interfaceName));
return isset($_ALL_CLASSES['implementors'][$interfaceName][$className]);
} }
/** /**
@ -215,11 +195,11 @@ class ClassInfo {
* @return array * @return array
*/ */
static function classes_for_file($filePath) { static function classes_for_file($filePath) {
$absFilePath = Director::getAbsFile($filePath); $absFilePath = Director::getAbsFile($filePath);
global $_CLASS_MANIFEST;
$matchedClasses = array(); $matchedClasses = array();
foreach($_CLASS_MANIFEST as $class => $compareFilePath) { $manifest = SS_ClassLoader::instance()->getManifest()->getClasses();
foreach($manifest as $class => $compareFilePath) {
if($absFilePath == $compareFilePath) $matchedClasses[] = $class; if($absFilePath == $compareFilePath) $matchedClasses[] = $class;
} }
@ -236,11 +216,11 @@ class ClassInfo {
* @return array Array of class names * @return array Array of class names
*/ */
static function classes_for_folder($folderPath) { static function classes_for_folder($folderPath) {
$absFolderPath = Director::getAbsFile($folderPath); $absFolderPath = Director::getAbsFile($folderPath);
global $_CLASS_MANIFEST;
$matchedClasses = array(); $matchedClasses = array();
foreach($_CLASS_MANIFEST as $class => $compareFilePath) { $manifest = SS_ClassLoader::instance()->getManifest()->getClasses();
foreach($manifest as $class => $compareFilePath) {
if(stripos($compareFilePath, $absFolderPath) === 0) $matchedClasses[] = $class; if(stripos($compareFilePath, $absFolderPath) === 0) $matchedClasses[] = $class;
} }

View File

@ -305,16 +305,10 @@ function getTempFolder($base = null) {
} }
/** /**
* Return the file where that class is stored. * @deprecated 3.0 Please use {@link SS_ClassManifest::getItemPath()}.
*
* @param String $className Case-insensitive lookup.
* @return String
*/ */
function getClassFile($className) { function getClassFile($className) {
global $_CLASS_MANIFEST; return SS_ClassLoader::instance()->getManifest()->getItemPath($className);
$lClassName = strtolower($className);
if(isset($_CLASS_MANIFEST[$lClassName])) return $_CLASS_MANIFEST[$lClassName];
else if(isset($_CLASS_MANIFEST[$className])) return $_CLASS_MANIFEST[$className];
} }
/** /**

6
core/i18n.php Executable file → Normal file
View File

@ -1703,11 +1703,11 @@ class i18n extends Object {
} }
// $name is assumed to be a PHP class // $name is assumed to be a PHP class
else { else {
global $_CLASS_MANIFEST; $classes = SS_ClassLoader::instance()->getManifest()->getClasses();
if(strpos($name,'_') !== false) $name = strtok($name,'_'); if(strpos($name,'_') !== false) $name = strtok($name,'_');
$name = strtolower($name); // Necessary because of r101131 $name = strtolower($name); // Necessary because of r101131
if(isset($_CLASS_MANIFEST[$name])) { if(isset($classes[$name])) {
$path = str_replace('\\','/',Director::makeRelative($_CLASS_MANIFEST[$name])); $path = str_replace('\\','/',Director::makeRelative($classes[$name]));
ereg('/([^/]+)/', $path, $module); ereg('/([^/]+)/', $path, $module);
} }
} }

View File

@ -91,9 +91,8 @@ class DatabaseAdmin extends Controller {
increase_time_limit_to(600); increase_time_limit_to(600);
// Get all our classes // Get all our classes
ManifestBuilder::create_manifest_file(); SS_ClassLoader::instance()->getManifest()->regenerate();
require(MANIFEST_FILE);
if(isset($_GET['returnURL'])) { if(isset($_GET['returnURL'])) {
echo "<p>Setting up the database; you will be returned to your site shortly....</p>"; echo "<p>Setting up the database; you will be returned to your site shortly....</p>";
$this->doBuild(true); $this->doBuild(true);

View File

@ -128,11 +128,12 @@ class ModelViewer_Model extends ViewableData {
} }
function getModule() { function getModule() {
global $_CLASS_MANIFEST; $classes = SS_ClassLoader::instance()->getManifest()->getClasses();
$className = strtolower($this->className); $className = strtolower($this->className);
if(($pos = strpos($className,'_')) !== false) $className = substr($className,0,$pos); if(($pos = strpos($className,'_')) !== false) $className = substr($className,0,$pos);
if(isset($_CLASS_MANIFEST[$className])) { if(isset($classes[$className])) {
if(preg_match('/^'.str_replace('/','\/',preg_quote(BASE_PATH)).'\/([^\/]+)\//', $_CLASS_MANIFEST[$className], $matches)) { if(preg_match('/^'.str_replace('/','\/',preg_quote(BASE_PATH)).'\/([^\/]+)\//', $classes[$className], $matches)) {
return $matches[1]; return $matches[1];
} }
} }

View File

@ -49,7 +49,7 @@ PHP
} }
function testClassDefParser() { function testClassDefParser() {
$parser = ManifestBuilder::getClassDefParser(); $parser = SS_ClassManifest::get_class_parser();
$tokens = $this->getTokens(); $tokens = $this->getTokens();
@ -79,7 +79,7 @@ PHP
} }
function testInterfaceDefParser() { function testInterfaceDefParser() {
$parser = ManifestBuilder::getInterfaceDefParser(); $parser = SS_ClassManifest::get_interface_parser();
$tokens = $this->getTokens(); $tokens = $this->getTokens();