public function reBuild() { $classPath = 'Classes/'; foreach ($GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes'] as $key => $extensionsWithThisClass) { $extendingClassFound = false; $path = ExtensionManagementUtility::extPath('news') . $classPath . $key . '.php'; if (!is_file($path)) { throw new \Exception('Given file "' . $path . '" does not exist'); } $code = $this->parseSingleFile($path, true); // Get the files from all other extensions foreach ($extensionsWithThisClass as $extensionKey) { $path = ExtensionManagementUtility::extPath($extensionKey) . $classPath . $key . '.php'; if (is_file($path)) { $extendingClassFound = true; $code .= $this->parseSingleFile($path, false); } } $code = $this->closeClassDefinition($code); // If an extending class is found, the file is written and // added to the autoloader info if ($extendingClassFound) { $cacheEntryIdentifier = 'tx_news_' . strtolower(str_replace('/', '_', $key)); try { $this->cacheInstance->set($cacheEntryIdentifier, $code); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } } } }
/** * Rebuild the class cache * * @param array $parameters * * @throws \Evoweb\Extender\Exception\FileNotFoundException * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException * @return void */ public function reBuild(array $parameters = array()) { if (empty($parameters) || !empty($parameters['cacheCmd']) && GeneralUtility::inList('all,system', $parameters['cacheCmd']) && isset($GLOBALS['BE_USER'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'] as $extensionKey => $extensionConfiguration) { if (!isset($extensionConfiguration['extender']) || !is_array($extensionConfiguration['extender'])) { continue; } foreach ($extensionConfiguration['extender'] as $entity => $entityConfiguration) { $key = 'Domain/Model/' . $entity; // Get the file to extend, this needs to be loaded as first $path = ExtensionManagementUtility::extPath($extensionKey) . 'Classes/' . $key . '.php'; if (!is_file($path)) { throw new \Evoweb\Extender\Exception\FileNotFoundException('given file "' . $path . '" does not exist'); } $code = $this->parseSingleFile($path, false); // Get the files from all other extensions that are extending this domain model if (is_array($entityConfiguration)) { foreach ($entityConfiguration as $extendingExtension => $extendingFilepath) { $path = GeneralUtility::getFileAbsFileName($extendingFilepath, false); if (!is_file($path) && !is_numeric($extendingExtension)) { $path = ExtensionManagementUtility::extPath($extendingExtension) . 'Classes/' . $key . '.php'; } $code .= $this->parseSingleFile($path); } } // Close the class definition $code = $this->closeClassDefinition($code); // Add the new file to the class cache $cacheEntryIdentifier = GeneralUtility::underscoredToLowerCamelCase($extensionKey) . '_' . str_replace('/', '', $key); $this->cacheInstance->set($cacheEntryIdentifier, $code); } } } }
/** * Save package namespaces and classes paths to cache * * @return void */ protected function savePackageNamespacesAndClassesPathsToCache() { $cacheEntryIdentifier = $this->getCacheEntryIdentifier(); if ($cacheEntryIdentifier !== NULL) { $this->coreCache->set($this->getCacheEntryIdentifier(), 'return ' . var_export(array($this->packageNamespaces, $this->packageClassesPaths), TRUE) . ';'); } }
/** * @param string $entryIdentifier * @param string $sourceCode * @param array $tags * @param int $lifetime * @throws InvalidDataException */ public function set($entryIdentifier, $sourceCode, array $tags = array(), $lifetime = null) { if (strpos($sourceCode, '<?php') === 0) { // Remove opening PHP tag; it is added by the cache backend to which // we delegate and would be duplicated if not removed. $sourceCode = substr($sourceCode, 6); } parent::set($entryIdentifier, $sourceCode, $tags, time() + 86400); }
/** * Saves the current state of all relevant information to the TYPO3 Core Cache */ protected function saveToPackageCache() { $cacheEntryIdentifier = $this->getCacheEntryIdentifier(); if ($cacheEntryIdentifier !== null && !$this->coreCache->has($cacheEntryIdentifier)) { // Package objects get their own cache entry, so PHP does not have to parse the serialized string $packageObjectsCacheEntryIdentifier = StringUtility::getUniqueId('PackageObjects_'); // Build cache file $packageCache = array('packageStatesConfiguration' => $this->packageStatesConfiguration, 'packageAliasMap' => $this->packageAliasMap, 'packageKeys' => $this->packageKeys, 'activePackageKeys' => array_keys($this->activePackages), 'requiredPackageKeys' => $this->requiredPackageKeys, 'loadedExtArray' => $GLOBALS['TYPO3_LOADED_EXT'], 'packageObjectsCacheEntryIdentifier' => $packageObjectsCacheEntryIdentifier); $this->coreCache->set($packageObjectsCacheEntryIdentifier, serialize($this->packages)); $this->coreCache->set($cacheEntryIdentifier, 'return ' . PHP_EOL . var_export($packageCache, true) . ';'); } }
/** * Saves the current state of all relevant information to the TYPO3 Core Cache */ protected function saveToPackageCache() { $cacheEntryIdentifier = $this->getCacheEntryIdentifier(); if ($cacheEntryIdentifier !== NULL && !$this->coreCache->has($cacheEntryIdentifier)) { // Package objects get their own cache entry, so PHP does not have to parse the serialized string $packageObjectsCacheEntryIdentifier = str_replace('.', '', uniqid('PackageObjects_', TRUE)); // Build cache file $packageCache = array('packageStatesConfiguration' => $this->packageStatesConfiguration, 'packageAliasMap' => $this->packageAliasMap, 'packageKeys' => $this->packageKeys, 'activePackageKeys' => array_keys($this->activePackages), 'requiredPackageKeys' => $this->requiredPackageKeys, 'loadedExtArray' => $GLOBALS['TYPO3_LOADED_EXT'], 'packageObjectsCacheEntryIdentifier' => $packageObjectsCacheEntryIdentifier); // Add the reflection of the package class $packageClassName = strtolower(Package::class); $reflectionPackageClass = new \ReflectionClass($packageClassName); $packageClassSource = file_get_contents($reflectionPackageClass->getFileName()); $packageClassSource = preg_replace('/<\\?php|\\?>/i', '', $packageClassSource); $this->coreCache->set($packageObjectsCacheEntryIdentifier, serialize($this->packages)); $this->coreCache->set($cacheEntryIdentifier, $packageClassSource . PHP_EOL . 'return ' . PHP_EOL . var_export($packageCache, TRUE) . ';'); } }
/** * */ protected function saveToPackageCache() { $cacheEntryIdentifier = $this->getCacheEntryIdentifier(); if ($cacheEntryIdentifier !== NULL && !$this->coreCache->has($cacheEntryIdentifier)) { // Package objects get their own cache entry, so PHP does not have to parse the serialized string $packageObjectsCacheEntryIdentifier = uniqid('PackageObjects_'); // Build cache file $packageCache = array('packageStatesConfiguration' => $this->packageStatesConfiguration, 'packageAliasMap' => $this->packageAliasMap, 'packageKeys' => $this->packageKeys, 'activePackageKeys' => array_keys($this->activePackages), 'requiredPackageKeys' => $this->requiredPackageKeys, 'loadedExtArray' => $GLOBALS['TYPO3_LOADED_EXT'], 'packageObjectsCacheEntryIdentifier' => $packageObjectsCacheEntryIdentifier); $packageClassSources = array('typo3\\flow\\package\\package' => NULL, 'typo3\\cms\\core\\package\\package' => NULL); foreach ($this->packages as $package) { $packageClassName = strtolower(get_class($package)); if (!isset($packageClassSources[$packageClassName]) || $packageClassSources[$packageClassName] === NULL) { $reflectionPackageClass = new \ReflectionClass($packageClassName); $packageClassSource = file_get_contents($reflectionPackageClass->getFileName()); $packageClassSources[$packageClassName] = preg_replace('/<\\?php|\\?>/i', '', $packageClassSource); } } $this->coreCache->set($packageObjectsCacheEntryIdentifier, serialize($this->packages)); $this->coreCache->set($cacheEntryIdentifier, implode(PHP_EOL, $packageClassSources) . PHP_EOL . 'return ' . PHP_EOL . var_export($packageCache, TRUE) . ';'); } }
/** * @param string $identifier * @param \TYPO3\CMS\Fluid\Core\Parser\ParsingState $parsingState * @return void */ public function store($identifier, \TYPO3\CMS\Fluid\Core\Parser\ParsingState $parsingState) { $identifier = $this->sanitizeIdentifier($identifier); $this->variableCounter = 0; $generatedRenderFunctions = ''; if ($parsingState->getVariableContainer()->exists('sections')) { $sections = $parsingState->getVariableContainer()->get('sections'); // @todo refactor to $parsedTemplate->getSections() foreach ($sections as $sectionName => $sectionRootNode) { $generatedRenderFunctions .= $this->generateCodeForSection($this->convertListOfSubNodes($sectionRootNode), 'section_' . sha1($sectionName), 'section ' . $sectionName); } } $generatedRenderFunctions .= $this->generateCodeForSection($this->convertListOfSubNodes($parsingState->getRootNode()), 'render', 'Main Render function'); $convertedLayoutNameNode = $parsingState->hasLayout() ? $this->convert($parsingState->getLayoutNameNode()) : array('initialization' => '', 'execution' => 'NULL'); $classDefinition = 'class FluidCache_' . $identifier . ' extends \\TYPO3\\CMS\\Fluid\\Core\\Compiler\\AbstractCompiledTemplate'; $templateCode = <<<EOD %s { public function getVariableContainer() { \t// @todo \treturn new \\TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer(); } public function getLayoutName(\\TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContextInterface \$renderingContext) { \$currentVariableContainer = \$renderingContext->getTemplateVariableContainer(); %s return %s; } public function hasLayout() { return %s; } %s } EOD; $templateCode = sprintf($templateCode, $classDefinition, $convertedLayoutNameNode['initialization'], $convertedLayoutNameNode['execution'], $parsingState->hasLayout() ? 'TRUE' : 'FALSE', $generatedRenderFunctions); $this->templateCache->set($identifier, $templateCode); }