public function _callbackGetValidThemeOptions() { $environmentDetectorService = tubepress_impl_patterns_sl_ServiceLocator::getEnvironmentDetector(); $fileSystemService = tubepress_impl_patterns_sl_ServiceLocator::getFileSystem(); $fileSystemFinderFactoryService = tubepress_impl_patterns_sl_ServiceLocator::getFileSystemFinderFactory(); $systemThemesDirectory = TUBEPRESS_ROOT . '/src/main/resources/default-themes'; $userThemesDirectory = $environmentDetectorService->getUserContentDirectory() . '/themes'; $directoriesToSearch = array(); if ($fileSystemService->exists($systemThemesDirectory)) { $directoriesToSearch[] = $systemThemesDirectory; } if ($fileSystemService->exists($userThemesDirectory)) { $directoriesToSearch[] = $userThemesDirectory; } $finder = $fileSystemFinderFactoryService->createFinder(); $finder->directories()->in($directoriesToSearch)->depth(0); $themeNames = array(); /** * @var $themeDirectory SplFileInfo */ foreach ($finder as $themeDirectory) { $themeNames[] = basename($themeDirectory->getBasename()); } sort($themeNames); $toReturn = array(); foreach ($themeNames as $themeName) { $toReturn[$themeName] = $themeName; } ksort($toReturn); return $toReturn; }
/** * This is public for test purposes only! * * @internal */ public function _findAddonsInDirectory($directory) { if (!is_dir($directory)) { return array(); } $finderFactory = tubepress_impl_patterns_sl_ServiceLocator::getFileSystemFinderFactory(); $finder = $finderFactory->createFinder()->followLinks()->files()->in($directory)->name('*.json')->depth('< 2'); $toReturn = array(); /** * @var $infoFile SplFileInfo */ foreach ($finder as $infoFile) { $addon = $this->_tryToBuildAddonFromFile($infoFile); if ($addon !== null) { if ($this->_shouldLog) { $this->_logger->debug('Found valid add-on at ' . $infoFile->getRealpath()); } $toReturn[] = $addon; } } if ($this->_shouldLog) { $this->_logger->debug(sprintf('Found %d add-on(s) from %s', count($toReturn), $directory)); } return $toReturn; }