Beispiel #1
0
 /**
  * Reads the specified class file, appends ORIGINAL_CLASSNAME_SUFFIX to its
  * class name and stores the result in the proxy classes cache.
  *
  * @param string $className Short class name of the class to copy
  * @param string $pathAndFilename Full path and filename of the original class file
  * @return void
  */
 protected function cacheOriginalClassFile($className, $pathAndFilename)
 {
     $classCode = file_get_contents($pathAndFilename);
     $classCode = preg_replace('/^<\\?php.*\\n/', '', $classCode);
     $classCode = preg_replace('/^([a-z ]*)(interface|class)\\s+([a-zA-Z0-9_]+)/m', '$1$2 $3' . self::ORIGINAL_CLASSNAME_SUFFIX, $classCode);
     $classCode = preg_replace('/\\?>[\\n\\s\\r]*$/', '', $classCode);
     $this->classesCache->set(str_replace('\\', '_', $className . self::ORIGINAL_CLASSNAME_SUFFIX), $classCode);
 }
Beispiel #2
0
 /**
  * Loads php files containing classes or interfaces found in the classes directory of
  * a package and specifically registered classes.
  *
  * @param string $className Name of the class/interface to load
  * @return boolean
  */
 public function loadClass($className)
 {
     if ($className[0] === '\\') {
         $className = substr($className, 1);
     }
     // Loads any known proxied class:
     if ($this->classesCache !== NULL && $this->classesCache->requireOnce(str_replace('\\', '_', $className)) !== FALSE) {
         return TRUE;
     }
     // Workaround for Doctrine's annotation parser which does a class_exists() for annotations like "@param" and so on:
     if (isset($this->ignoredClassNames[$className]) || isset($this->ignoredClassNames[substr($className, strrpos($className, '\\') + 1)])) {
         return FALSE;
     }
     // Load classes from the FLOW3 package at a very early stage where
     // no packages have been registered yet:
     if ($this->packages === array() && substr($className, 0, 11) === 'TYPO3\\FLOW3') {
         require FLOW3_PATH_FLOW3 . 'Classes/' . str_replace('\\', '/', substr($className, 12)) . '.php';
         return TRUE;
     }
     // Loads any non-proxied class of registered packages:
     foreach ($this->packageNamespaces as $packageNamespace => $packageData) {
         if (substr($className, 0, $packageData['namespaceLength']) === $packageNamespace) {
             if ($this->considerTestsNamespace === TRUE && substr($className, $packageData['namespaceLength'] + 1, 16) === 'Tests\\Functional') {
                 $classPathAndFilename = $this->packages[str_replace('\\', '.', $packageNamespace)]->getPackagePath() . str_replace('\\', '/', substr($className, $packageData['namespaceLength'] + 1)) . '.php';
                 if (file_exists($classPathAndFilename)) {
                     require $classPathAndFilename;
                     return TRUE;
                 }
             } else {
                 // The only reason using file_exists here is that Doctrine tries
                 // out several combinations of annotation namespaces and thus also triggers
                 // autoloading for non-existent classes in a valid package namespace
                 $classPathAndFilename = $packageData['classesPath'] . str_replace('\\', '/', substr($className, $packageData['namespaceLength'])) . '.php';
                 if (file_exists($classPathAndFilename)) {
                     require $classPathAndFilename;
                     return TRUE;
                 }
             }
         }
     }
     return FALSE;
 }