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

View File

@ -305,16 +305,10 @@ function getTempFolder($base = null) {
}
/**
* Return the file where that class is stored.
*
* @param String $className Case-insensitive lookup.
* @return String
* @deprecated 3.0 Please use {@link SS_ClassManifest::getItemPath()}.
*/
function getClassFile($className) {
global $_CLASS_MANIFEST;
$lClassName = strtolower($className);
if(isset($_CLASS_MANIFEST[$lClassName])) return $_CLASS_MANIFEST[$lClassName];
else if(isset($_CLASS_MANIFEST[$className])) return $_CLASS_MANIFEST[$className];
return SS_ClassLoader::instance()->getManifest()->getItemPath($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
else {
global $_CLASS_MANIFEST;
$classes = SS_ClassLoader::instance()->getManifest()->getClasses();
if(strpos($name,'_') !== false) $name = strtok($name,'_');
$name = strtolower($name); // Necessary because of r101131
if(isset($_CLASS_MANIFEST[$name])) {
$path = str_replace('\\','/',Director::makeRelative($_CLASS_MANIFEST[$name]));
if(isset($classes[$name])) {
$path = str_replace('\\','/',Director::makeRelative($classes[$name]));
ereg('/([^/]+)/', $path, $module);
}
}

View File

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

View File

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

View File

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