Пример #1
0
 /**
  * @test
  */
 public function classesWithLeadingBackslashAreLoaded()
 {
     mkdir('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp', 0770, TRUE);
     file_put_contents('vfs://Test/Packages/Application/Acme.MyApp/Classes/Acme/MyApp/WithLeadingBackslash.php', '<?php ' . __CLASS__ . '::$testClassWasLoaded = TRUE; ?>');
     self::$testClassWasLoaded = FALSE;
     $this->classLoader->loadClass('\\Acme\\MyApp\\WithLeadingBackslash');
     $this->assertTrue(self::$testClassWasLoaded);
 }
Пример #2
0
 /**
  * Enables packages during runtime, but no class aliases will be available
  *
  * @param string $packageKey
  * @api
  */
 public function activatePackageDuringRuntime($packageKey)
 {
     $package = $this->getPackage($packageKey);
     $this->runtimeActivatedPackages[$package->getPackageKey()] = $package;
     $this->classLoader->addActivePackage($package);
     if (!isset($GLOBALS['TYPO3_LOADED_EXT'][$package->getPackageKey()])) {
         $loadedExtArrayElement = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionArrayElement($package);
         $GLOBALS['TYPO3_LOADED_EXT'][$package->getPackageKey()] = $loadedExtArrayElement->toArray();
     }
 }
 /**
  * Returns the class name for a new instance, taking into account
  * registered implementations for this class
  *
  * @param string $className Base class name to evaluate
  * @return string Final class name to instantiate with "new [classname]
  */
 protected static function getClassName($className)
 {
     if (class_exists($className)) {
         while (static::classHasImplementation($className)) {
             $className = static::getImplementationForClass($className);
         }
     }
     return \TYPO3\CMS\Core\Core\ClassLoader::getClassNameForAlias($className);
 }
Пример #4
0
 /**
  * Things that should be performed to shut down the framework.
  * This method is called in all important scripts for a clean
  * shut down of the system.
  *
  * @return \TYPO3\CMS\Core\Core\Bootstrap
  * @internal This is not a public API method, do not use in own extensions
  */
 public function shutdown()
 {
     if (PHP_VERSION_ID < 50307) {
         \TYPO3\CMS\Core\Compatibility\CompatbilityClassLoaderPhpBelow50307::unregisterAutoloader();
     } else {
         \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader();
     }
     return $this;
 }
Пример #5
0
 /**
  * Internal implementation for getting a class.
  *
  * @param string $className
  * @param array $givenConstructorArguments the list of constructor arguments as array
  * @throws \TYPO3\CMS\Extbase\Object\Exception
  * @throws \TYPO3\CMS\Extbase\Object\Exception\CannotBuildObjectException
  * @return object the built object
  */
 protected function getInstanceInternal($className, $givenConstructorArguments = array())
 {
     // Never instantiate with a beginning backslash, otherwise things like singletons won't work.
     if ($className[0] === '\\') {
         $className = substr($className, 1);
     }
     $className = $this->getImplementationClassName($className);
     if ($className === 'TYPO3\\CMS\\Extbase\\Object\\Container\\Container') {
         return $this;
     }
     if ($className === 'TYPO3\\CMS\\Core\\Cache\\CacheManager') {
         return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
     }
     if ($className === 'TYPO3\\CMS\\Core\\Package\\PackageManager') {
         return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager');
     }
     $className = \TYPO3\CMS\Core\Core\ClassLoader::getClassNameForAlias($className);
     if (isset($this->singletonInstances[$className])) {
         if (count($givenConstructorArguments) > 0) {
             throw new \TYPO3\CMS\Extbase\Object\Exception('Object "' . $className . '" fetched from singleton cache, thus, explicit constructor arguments are not allowed.', 1292857934);
         }
         return $this->singletonInstances[$className];
     }
     $classInfo = $this->getClassInfo($className);
     $classIsSingleton = $classInfo->getIsSingleton();
     if (!$classIsSingleton) {
         if (array_key_exists($className, $this->prototypeObjectsWhichAreCurrentlyInstanciated) !== FALSE) {
             throw new \TYPO3\CMS\Extbase\Object\Exception\CannotBuildObjectException('Cyclic dependency in prototype object, for class "' . $className . '".', 1295611406);
         }
         $this->prototypeObjectsWhichAreCurrentlyInstanciated[$className] = TRUE;
     }
     $instance = $this->instanciateObject($classInfo, $givenConstructorArguments);
     $this->injectDependencies($instance, $classInfo);
     if ($classInfo->getIsInitializeable() && is_callable(array($instance, 'initializeObject'))) {
         $instance->initializeObject();
     }
     if (!$classIsSingleton) {
         unset($this->prototypeObjectsWhichAreCurrentlyInstanciated[$className]);
     }
     return $instance;
 }
Пример #6
0
 /**
  * @test
  */
 public function checkAutoloaderSetsNamespacedClassnamesInExtAutoloadAreWrittenToCache()
 {
     $extKey = $this->createFakeExtension();
     $extPath = PATH_site . 'typo3temp/' . $extKey . '/';
     $pathSegment = 'Foo' . uniqid();
     $fileName = 'Bar' . uniqid();
     $autoloaderFile = $extPath . 'ext_autoload.php';
     // A case sensitive key (FooBar) in ext_autoload file
     $namespacedClass = '\\Tx\\' . $extKey . '\\' . $pathSegment . '\\' . $fileName;
     $classFile = 'EXT:someExt/Classes/Foo/bar.php';
     file_put_contents($autoloaderFile, '<?php' . LF . 'return ' . var_export(array($namespacedClass => $classFile), TRUE) . ';' . LF . '?>');
     // Inject a dummy for the core_phpcode cache to force the autoloader
     // to re calculate the registry
     $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
     $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
     $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
     // Expect that the lower case version of the class name is written to cache
     $mockCache->expects($this->at(2))->method('set')->with($this->anything(), $this->stringContains(strtolower(addslashes($namespacedClass)), FALSE));
     // Re-initialize autoloader registry to force it to recognize the new extension
     \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader();
     \TYPO3\CMS\Core\Core\ClassLoader::registerAutoloader();
     \TYPO3\CMS\Core\Core\ClassLoader::unregisterAutoloader();
 }
Пример #7
0
 /**
  * Resolve a viewhelper name.
  *
  * @param string $namespaceIdentifier Namespace identifier for the view helper.
  * @param string $methodIdentifier Method identifier, might be hierarchical like "link.url"
  * @return string The fully qualified class name of the viewhelper
  */
 protected function resolveViewHelperName($namespaceIdentifier, $methodIdentifier)
 {
     if (isset($this->viewHelperNameToImplementationClassNameRuntimeCache[$namespaceIdentifier][$methodIdentifier])) {
         $name = $this->viewHelperNameToImplementationClassNameRuntimeCache[$namespaceIdentifier][$methodIdentifier];
     } else {
         $explodedViewHelperName = explode('.', $methodIdentifier);
         $namespaceSeparator = strpos($this->namespaces[$namespaceIdentifier], \TYPO3\CMS\Fluid\Fluid::NAMESPACE_SEPARATOR) !== FALSE ? \TYPO3\CMS\Fluid\Fluid::NAMESPACE_SEPARATOR : \TYPO3\CMS\Fluid\Fluid::LEGACY_NAMESPACE_SEPARATOR;
         if (count($explodedViewHelperName) > 1) {
             $className = implode($namespaceSeparator, array_map('ucfirst', $explodedViewHelperName));
         } else {
             $className = ucfirst($explodedViewHelperName[0]);
         }
         $className .= 'ViewHelper';
         $name = $this->namespaces[$namespaceIdentifier] . $namespaceSeparator . $className;
         $name = \TYPO3\CMS\Core\Core\ClassLoader::getClassNameForAlias($name);
         // The name isn't cached in viewHelperNameToImplementationClassNameRuntimeCache here because the
         // class could be overloaded by extbase object manager. Thus the cache is filled in
         // initializeViewHelperAndAddItToStack after getting the real object from the object manager.
     }
     return $name;
 }
 /**
  * Unload TYPO3 autoloader and write any additional classes
  * found during the script run to the cache file.
  *
  * This method is called during shutdown of the framework.
  *
  * @return boolean TRUE in case of success
  */
 public static function unregisterAutoloader()
 {
     return parent::unregisterAutoloader();
 }
 /**
  * Set a single option (denoted by $optionKey) for the given $typeConverter.
  *
  * @param string $typeConverter class name of type converter
  * @param string $optionKey
  * @param mixed $optionValue
  * @return \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration this
  * @api
  */
 public function setTypeConverterOption($typeConverter, $optionKey, $optionValue)
 {
     if (strpos($typeConverter, '_') !== FALSE) {
         $typeConverter = ClassLoader::getClassNameForAlias($typeConverter);
     }
     foreach ($this->getTypeConvertersWithParentClasses($typeConverter) as $typeConverter) {
         $this->configuration[$typeConverter][$optionKey] = $optionValue;
     }
     return $this;
 }
Пример #10
0
 /**
  * Determine the type converter to be used. If no converter has been found, an exception is raised.
  *
  * @param mixed $source
  * @param string $targetType
  * @param PropertyMappingConfigurationInterface $configuration
  * @throws Exception\TypeConverterException
  * @throws Exception\InvalidTargetException
  * @return \TYPO3\CMS\Extbase\Property\TypeConverterInterface Type Converter which should be used to convert between $source and $targetType.
  */
 protected function findTypeConverter($source, $targetType, PropertyMappingConfigurationInterface $configuration)
 {
     if ($configuration->getTypeConverter() !== NULL) {
         return $configuration->getTypeConverter();
     }
     $sourceType = $this->determineSourceType($source);
     if (!is_string($targetType)) {
         throw new Exception\InvalidTargetException('The target type was no string, but of type "' . gettype($targetType) . '"', 1297941727);
     }
     $targetType = $this->parseCompositeType($targetType);
     // This is needed to correctly convert old class names to new ones
     // This compatibility layer will be removed with 7.0
     $targetType = \TYPO3\CMS\Core\Core\ClassLoader::getClassNameForAlias($targetType);
     $converter = NULL;
     if (\TYPO3\CMS\Extbase\Utility\TypeHandlingUtility::isSimpleType($targetType)) {
         if (isset($this->typeConverters[$sourceType][$targetType])) {
             $converter = $this->findEligibleConverterWithHighestPriority($this->typeConverters[$sourceType][$targetType], $source, $targetType);
         }
     } else {
         $converter = $this->findFirstEligibleTypeConverterInObjectHierarchy($source, $sourceType, $targetType);
     }
     if ($converter === NULL) {
         throw new Exception\TypeConverterException('No converter found which can be used to convert from "' . $sourceType . '" to "' . $targetType . '".');
     }
     return $converter;
 }