Exemplo n.º 1
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 Flow package at a very early stage where
     // no packages have been registered yet:
     if ($this->packages === array() && substr($className, 0, 10) === 'TYPO3\\Flow') {
         require FLOW_PATH_FLOW . 'Classes/TYPO3/Flow/' . str_replace('\\', '/', substr($className, 11)) . '.php';
         return TRUE;
     }
     // Loads any non-proxied class of registered packages:
     foreach ($this->packageNamespaces as $packageNamespace => $packageData) {
         // replace underscores in classname with \ to match for packagenamespace
         if (substr(str_replace('_', '\\', $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';
             } else {
                 // make the classname PSR-0 compliant by replacing underscores only in the classname not in the namespace
                 $fileName = '';
                 $lastNamespacePosition = strrpos($className, '\\');
                 if ($lastNamespacePosition !== FALSE) {
                     $namespace = substr($className, 0, $lastNamespacePosition);
                     $className = substr($className, $lastNamespacePosition + 1);
                     $fileName = str_replace('\\', '/', $namespace) . '/';
                 }
                 $fileName .= str_replace('_', '/', $className) . '.php';
                 $classPathAndFilename = $packageData['classesPath'] . $fileName;
             }
             try {
                 $result = (include $classPathAndFilename);
                 if ($result !== FALSE) {
                     return TRUE;
                 }
             } catch (\Exception $e) {
             }
         }
     }
     return FALSE;
 }
 /**
  * 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 = ltrim($className, '\\');
     }
     $namespaceParts = explode('\\', $className);
     // 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[end($namespaceParts)]) || isset($this->nonExistentClasses[$className])) {
         return false;
     }
     // Loads any known proxied class:
     if ($this->classesCache !== null && ($this->availableProxyClasses === null || isset($this->availableProxyClasses[implode('_', $namespaceParts)])) && $this->classesCache->requireOnce(implode('_', $namespaceParts)) !== false) {
         return true;
     }
     if (isset($this->classMap[$className])) {
         include $this->classMap[$className];
         return true;
     }
     $classNamePart = array_pop($namespaceParts);
     $classNameParts = explode('_', $classNamePart);
     $namespaceParts = array_merge($namespaceParts, $classNameParts);
     $namespacePartCount = count($namespaceParts);
     // Load classes from the Flow package at a very early stage where no packages have been registered yet:
     if ($this->packageNamespaces === array()) {
         if ($namespaceParts[0] === 'TYPO3' && $namespaceParts[1] === 'Flow') {
             require FLOW_PATH_FLOW . 'Classes/TYPO3/Flow/' . implode('/', array_slice($namespaceParts, 2)) . '.php';
             return true;
         } else {
             return false;
         }
     }
     $currentPackageArray = $this->packageNamespaces;
     $packagenamespacePartCount = 0;
     // This will contain all possible class mappings for the given class name. We start with the fallback paths and prepend mappings with growing specificy.
     $collectedPossibleNamespaceMappings = array(array('p' => $this->fallbackClassPaths, 'c' => 0));
     if ($namespacePartCount > 1) {
         while ($packagenamespacePartCount + 1 < $namespacePartCount) {
             $possiblePackageNamespacePart = $namespaceParts[$packagenamespacePartCount];
             if (!isset($currentPackageArray[$possiblePackageNamespacePart])) {
                 break;
             }
             $packagenamespacePartCount++;
             $currentPackageArray = $currentPackageArray[$possiblePackageNamespacePart];
             if (isset($currentPackageArray['_pathData'])) {
                 array_unshift($collectedPossibleNamespaceMappings, array('p' => $currentPackageArray['_pathData'], 'c' => $packagenamespacePartCount));
             }
         }
     }
     foreach ($collectedPossibleNamespaceMappings as $nameSpaceMapping) {
         if ($this->loadClassFromPossiblePaths($nameSpaceMapping['p'], $namespaceParts, $nameSpaceMapping['c'])) {
             return true;
         }
     }
     $this->nonExistentClasses[$className] = true;
     return false;
 }
 /**
  * Shutdown the Evaluator
  */
 public function shutdownObject()
 {
     if (count($this->newExpressions) > 0) {
         $changesToPersist = FALSE;
         $codeToBeCached = $this->expressionCache->get('cachedExpressionClosures');
         /**
          * At this point a race condition could happen, that we try to prevent with an additional check.
          * So we compare the evaluated expressions during this request with the methods the cache has at
          * this point and only add methods that are not present. Only if we added anything we write the cache.
          */
         foreach ($this->newExpressions as $functionName => $newExpression) {
             if (strpos($codeToBeCached, $functionName) === FALSE) {
                 $codeToBeCached .= $newExpression . chr(10);
                 $changesToPersist = TRUE;
             }
         }
         if ($changesToPersist) {
             $this->expressionCache->set('cachedExpressionClosures', $codeToBeCached);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Flush cached templates if a ViewHelper class is changed
  *
  * @param array $changedFiles An array of changed class files
  * @return void
  */
 public function flushTemplatesOnViewHelperChanges(array $changedFiles)
 {
     if (!$this->templateCache instanceof PhpFrontend) {
         return;
     }
     foreach ($changedFiles as $pathAndFilename => $status) {
         if (strrpos($pathAndFilename, 'ViewHelper.php') !== FALSE) {
             $this->templateCache->flush();
             return;
         }
     }
 }
Exemplo n.º 5
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
  * @param string $proxyClassCode The code that makes up the proxy class
  * @return void
  *
  * @throws Exception If the original class filename doesn't match the actual class name inside the file.
  */
 protected function cacheOriginalClassFileAndProxyCode($className, $pathAndFilename, $proxyClassCode)
 {
     $classCode = file_get_contents($pathAndFilename);
     $classCode = preg_replace('/^<\\?php.*\\n/', '', $classCode);
     $classNameSuffix = self::ORIGINAL_CLASSNAME_SUFFIX;
     $classCode = preg_replace_callback('/^([a-z ]*)(interface|class)\\s+([a-zA-Z0-9_]+)/m', function ($matches) use($pathAndFilename, $classNameSuffix) {
         $classNameAccordingToFileName = basename($pathAndFilename, '.php');
         if ($matches[3] !== $classNameAccordingToFileName) {
             throw new Exception('The name of the class "' . $matches[3] . '" is not the same as the filename which is "' . basename($pathAndFilename) . '". Path: ' . $pathAndFilename, 1398356897);
         }
         return $matches[1] . $matches[2] . ' ' . $matches[3] . $classNameSuffix;
     }, $classCode);
     $classCode = preg_replace('/\\?>[\\n\\s\\r]*$/', '', $classCode);
     $this->classesCache->set(str_replace('\\', '_', $className), $classCode . $proxyClassCode);
 }
 /**
  * Flush all runtime expressions
  *
  * @return void
  */
 public function flush()
 {
     $this->runtimeExpressionsCache->flush();
 }
Exemplo n.º 7
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 = ltrim($className, '\\');
     }
     $namespaceParts = explode('\\', $className);
     // 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[end($namespaceParts)]) || isset($this->nonExistentClasses[$className])) {
         return FALSE;
     }
     // Loads any known proxied class:
     if ($this->classesCache !== NULL && ($this->availableProxyClasses === NULL || isset($this->availableProxyClasses[implode('_', $namespaceParts)])) && $this->classesCache->requireOnce(implode('_', $namespaceParts)) !== FALSE) {
         return TRUE;
     }
     if (isset($this->classMap[$className])) {
         include $this->classMap[$className];
         return TRUE;
     }
     $classNamePart = array_pop($namespaceParts);
     $classNameParts = explode('_', $classNamePart);
     $namespaceParts = array_merge($namespaceParts, $classNameParts);
     $namespacePartCount = count($namespaceParts);
     // Load classes from the Flow package at a very early stage where
     // no packages have been registered yet:
     if ($this->packageNamespaces === array()) {
         if ($namespaceParts[0] === 'TYPO3' && $namespaceParts[1] === 'Flow') {
             require FLOW_PATH_FLOW . 'Classes/TYPO3/Flow/' . implode('/', array_slice($namespaceParts, 2)) . '.php';
             return TRUE;
         } else {
             return FALSE;
         }
     }
     $currentPackageArray = $this->packageNamespaces;
     $packagenamespacePartCount = 0;
     if ($namespacePartCount === 1 && isset($currentPackageArray[$namespaceParts[0]])) {
         $currentPackageArray = $currentPackageArray[$namespaceParts[0]];
     } else {
         while ($packagenamespacePartCount + 1 < $namespacePartCount) {
             $possiblePackageNamespacePart = $namespaceParts[$packagenamespacePartCount];
             if (!isset($currentPackageArray[$possiblePackageNamespacePart])) {
                 break;
             }
             $packagenamespacePartCount++;
             $currentPackageArray = $currentPackageArray[$possiblePackageNamespacePart];
         }
     }
     if (isset($currentPackageArray['_pathData'])) {
         $possiblePaths = $currentPackageArray['_pathData'];
     } else {
         $packagenamespacePartCount = 0;
         $possiblePaths = $this->fallbackClassPaths;
     }
     foreach ($possiblePaths as $possiblePathData) {
         $pathConstructor = 'buildClassPathWith' . $possiblePathData['mappingType'];
         $possibleFilePath = $this->{$pathConstructor}($namespaceParts, $possiblePathData['path'], $packagenamespacePartCount);
         if (file_exists($possibleFilePath)) {
             $result = (include $possibleFilePath);
             if ($result !== FALSE) {
                 return TRUE;
             }
         }
     }
     $this->nonExistentClasses[$className] = TRUE;
     return FALSE;
 }