Changeset 450

Show
Ignore:
Timestamp:
04/02/07 21:57:09 (2 years ago)
Author:
schst
Message:

Performance improvement and whitespace fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/stubClassLoader.php

    r448 r450  
    77/** 
    88 * Interface for class loaders that load classes from foreign namespaces. 
    9  *  
     9 * 
    1010 * This interface must reside here because the stubClassLoader uses it as type hint. 
    1111 * 
     
    2020     */ 
    2121    public function setNamespace($namespace); 
    22      
     22 
    2323    /** 
    2424     * returns the namespace where this classloader is responsible for 
     
    2727     */ 
    2828    public function getNamespace(); 
    29      
     29 
    3030    /** 
    3131     * loads the given class 
     
    6262     */ 
    6363    private static $foreignClassLoaders = array(); 
    64      
     64 
    6565    /** 
    6666     * method to load files from source path 
     
    8383            return; 
    8484        } 
    85          
     85 
    8686        $files   = array(); 
    8787        $dirName = self::getSourcePath(); 
     
    9191                continue; 
    9292            } 
    93              
     93 
    9494            self::$classNames[$nqClassName] = $fqClassName; 
    9595            $foreignNamespace = self::getForeignNamespace($fqClassName); 
    9696            if (null != $foreignNamespace) { 
    97                 self::$foreignClassLoaders[$foreignNamespace]->load($fqClassName); 
     97                self::$foreignClassLoaders[$foreignNamespace][0]->load($fqClassName); 
    9898                return; 
    9999            } 
    100              
     100 
    101101            $uri = null; 
    102102            if (stubConfig::useStar() == true && class_exists('StarClassRegistry', false) == true) { 
     
    107107            } 
    108108            require $uri; 
    109              
     109 
    110110            if (method_exists($nqClassName, '__static') == true) { 
    111111                call_user_func(array($nqClassName, '__static')); 
     
    113113        } 
    114114    } 
    115      
     115 
    116116    /** 
    117117     * returns the non qualified class name from a full qualified class name 
     
    125125        return $classNameParts[count($classNameParts) - 1]; 
    126126    } 
    127      
     127 
    128128    /** 
    129129     * returns the full qualified class name of a non qualified class name 
     
    137137            return self::$classNames[$nqClassName]; 
    138138        } 
    139          
     139 
    140140        return null; 
    141141    } 
    142      
     142 
    143143    /** 
    144144     * returns the path to the source files 
     
    154154        } 
    155155    } 
    156      
     156 
    157157    /** 
    158158     * registers a foreign class loader 
     
    162162    public static function registerForeignClassLoader(stubForeignClassLoader $foreignClassLoader) 
    163163    { 
    164         self::$foreignClassLoaders[$foreignClassLoader->getNamespace()] = $foreignClassLoader
     164        self::$foreignClassLoaders[$foreignClassLoader->getNamespace()] = array($foreignClassLoader, strlen($foreignClassLoader->getNamespace()))
    165165    } 
    166      
     166 
    167167    /** 
    168168     * checks whether a class resides in a foreign namespace 
     
    174174    { 
    175175        foreach (self::$foreignClassLoaders as $foreignNamespace => $foreignClassLoader) { 
    176            if (substr($fqClassName, 0, strlen($foreignNamespace)) == $foreignNamespace) { 
    177                return $foreignNamespace; 
    178            
     176            if (strncmp($fqClassName, $foreignNamespace, $foreignClassLoader[1]) === 0) { 
     177                return $foreignNamespace; 
     178           
    179179        } 
    180          
    181180        return null; 
    182181    } 
    183      
     182 
    184183    /** 
    185184     * maps a classname to corresponding file name