public static function getLocallangPaths(array $directories = null) { if ($directories === null) { $directories = array('typo3conf/ext/', 'typo3/sysext/'); $directories = array('typo3conf/ext/'); } $files = array(); // Traverse extension locations: foreach ($directories as $path) { $path = static::getAbsolutePath(\TYPO3\CMS\Core\Utility\PathUtility::sanitizeTrailingSeparator($path)); if (is_dir($path)) { $files = array_merge($files, GeneralUtility::getAllFilesAndFoldersInPath(array(), $path, 'xml,xlf', false, 99, 'Tests')); } } // Remove all non-locallang files (looking at the prefix) foreach ($files as $key => $value) { if (strpos(basename($value), 'locallang') !== 0) { unset($files[$key]); } else { $files[$key] = PathUtility::getTypo3PathTo($value); } } return $files; }
/** * Create a zip file from an extension * * @param array $extension * @return string Name and path of create zip file */ public function createZipFileFromExtension($extension) { $extensionPath = $this->getAbsoluteExtensionPath($extension); // Add trailing slash to the extension path, getAllFilesAndFoldersInPath explicitly requires that. $extensionPath = PathUtility::sanitizeTrailingSeparator($extensionPath); $version = $this->getExtensionVersion($extension); if (empty($version)) { $version = '0.0.0'; } if (!@is_dir(PATH_site . 'typo3temp/ExtensionManager/')) { GeneralUtility::mkdir(PATH_site . 'typo3temp/ExtensionManager/'); } $fileName = $this->getAbsolutePath('typo3temp/ExtensionManager/' . $extension . '_' . $version . '_' . date('YmdHi', $GLOBALS['EXEC_TIME']) . '.zip'); $zip = new \ZipArchive(); $zip->open($fileName, \ZipArchive::CREATE); $excludePattern = $GLOBALS['TYPO3_CONF_VARS']['EXT']['excludeForPackaging']; // Get all the files of the extension, but exclude the ones specified in the excludePattern $files = GeneralUtility::getAllFilesAndFoldersInPath(array(), $extensionPath, '', true, PHP_INT_MAX, $excludePattern); // Make paths relative to extension root directory. $files = GeneralUtility::removePrefixPathFromList($files, $extensionPath); // Remove the one empty path that is the extension dir itself. $files = array_filter($files); foreach ($files as $file) { $fullPath = $extensionPath . $file; // Distinguish between files and directories, as creation of the archive // fails on Windows when trying to add a directory with "addFile". if (is_dir($fullPath)) { $zip->addEmptyDir($file); } else { $zip->addFile($fullPath, $file); } } $zip->close(); return $fileName; }
/** * @param string $path * @param string $separator * @param string $expected * @dataProvider isTrailingSeparatorSanitizedCorrectlyDataProvider * @test */ public function isTrailingSeparatorSanitizedCorrectly($path, $separator, $expected) { $sanitizedPath = \TYPO3\CMS\Core\Utility\PathUtility::sanitizeTrailingSeparator($path, $separator); $this->assertEquals($expected, $sanitizedPath); }
/** * Scans all sub directories of the specified directory and collects the package keys of packages it finds. * * The return of the array is to make this method usable in array_merge. * * @param string $startPath * @param array $collectedPackagePaths * @return array */ protected function scanPackagesInPath($startPath, array $collectedPackagePaths) { foreach (new \DirectoryIterator($startPath) as $fileInfo) { if (!$fileInfo->isDir()) { continue; } $filename = $fileInfo->getFilename(); if ($filename[0] !== '.') { $currentPath = $fileInfo->getPathName(); $currentPath = PathUtility::sanitizeTrailingSeparator($currentPath); if ($this->hasComposerManifestFile($currentPath)) { $collectedPackagePaths[$currentPath] = $currentPath; } } } return $collectedPackagePaths; }
/** * Requires and registers all packages which were defined in packageStatesConfiguration * * @param bool $registerOnlyNewPackages * @return void */ protected function registerPackagesFromConfiguration($registerOnlyNewPackages = false) { $packageStatesHasChanged = false; foreach ($this->packageStatesConfiguration['packages'] as $packageKey => $stateConfiguration) { if ($registerOnlyNewPackages && $this->isPackageAvailable($packageKey)) { continue; } if (!isset($stateConfiguration['packagePath'])) { $this->unregisterPackageByPackageKey($packageKey); $packageStatesHasChanged = true; continue; } try { $packagePath = PathUtility::sanitizeTrailingSeparator($this->packagesBasePath . $stateConfiguration['packagePath']); $package = new Package($this, $packageKey, $packagePath); } catch (Exception\InvalidPackagePathException $exception) { $this->unregisterPackageByPackageKey($packageKey); $packageStatesHasChanged = true; continue; } catch (Exception\InvalidPackageKeyException $exception) { $this->unregisterPackageByPackageKey($packageKey); $packageStatesHasChanged = true; continue; } catch (Exception\InvalidPackageManifestException $exception) { $this->unregisterPackageByPackageKey($packageKey); $packageStatesHasChanged = true; continue; } $this->registerPackage($package, false); if ($stateConfiguration['state'] === 'active') { $this->activePackages[$packageKey] = $this->packages[$packageKey]; } } if ($packageStatesHasChanged) { $this->sortAndSavePackageStates(); } }