Publish all module resources

@param string $targetDir
@param array $extensions
540353
public function publish($targetDir = null, array $extensions = array())
    {
        if (!$targetDir) {
            $targetDir = $this->targetDir;
        }

        $this->publishResources($targetDir, $extensions);
        $this->publishThemeFiles($targetDir, $extensions);

        return $this;
    }
705048
private function _publishRegisteredResourcesUpdater(array $incResources)
    {
        $resourcesJson = json_encode($this->_prepareDataOnRegisteredResources($incResources));

        $this->_publishExtensionJs(
            array(
                '$(function () {',
                '    var app = %extensionObject%;',
                '    var resources = %resourcesJson%;',
                '    resources.map(function (dataObj) { ',
                '        app.addResource(dataObj.hash, dataObj.resource, dataObj.comment); ',
                '    });',
                '});',
            ),
            array(
                '%extensionObject%' => self::JS_GLOBAL_OBJ_PRIVATE_PATH,
                '%resourcesJson%'   => $resourcesJson,
            )
        );
    }
757544
public static function copy($originFile, $targetFile, $override = false)
    {
        self::ensureFileSystem()->copy($originFile, $targetFile, $override);
    }
385639
protected function _move($source, $targetDir, $name) {
		$target = $targetDir.DIRECTORY_SEPARATOR.$name;
		return ftp_rename($this->connect, $source, $target) ? $target : false;
	}
908316
private function publishResources()
    {
        $this->publishes([__DIR__.'/../../resources/config/defender.php' => config_path('defender.php')], 'config');
        $this->mergeConfigFrom(__DIR__.'/../../resources/config/defender.php', 'defender');
        $this->loadViewsFrom(__DIR__.'/../../resources/views', 'defender');
    }
812855
private function addExtension(
        array &$targets,
        string $target,
        string $extension,
        array $attributes
    ): void {
        if (!isset($targets[$target])) {
            $targets[$target] = new \SplPriorityQueue();
        }

        $priority = $attributes['priority'] ?? 0;
        $targets[$target]->insert(new Reference($extension), $priority);
    }
712858
public function publishNodesAction(array $nodes, $targetWorkspaceName  = null)
    {
        $targetWorkspace = ($targetWorkspaceName !== null) ? $this->workspaceRepository->findOneByName($targetWorkspaceName) : null;
        $this->publishingService->publishNodes($nodes, $targetWorkspace);

        $this->throwStatus(204, 'Nodes published', '');
    }
976300
protected function publishDirectory($from, $to)
    {
        $this->moveManagedFiles(new MountManager([
            'from' => new Flysystem(new LocalAdapter($from)),
            'to' => new Flysystem(new LocalAdapter($to)),
        ]));
    }
141423
protected function buildCollection(array $sources, array $extensions)
    {
        $collection = new Collection();
        $collection->setAllowedExtensions($extensions);
        foreach ($sources as $path) {
            if (is_dir($path)) {
                $collection->addDirectory($path);
                continue;
            }

            $collection->addFile($path);
        }

        return $collection;
    }
790812
private function publish_directories($directories)
    {
        $root = \get_template_directory();

        if (\is_child_theme()) {
            $root = \get_stylesheet_directory();
        }

        if (isset($this->root)) {
            $root = $this->root;
        }

        foreach ($directories as $source => $target) {
            $target_path = \trailingslashit($root) . \ltrim($target, '/\\');

            // Check if source exists.
            if (! \is_dir($source)) {
                $this->output->writeln("<error>The package source [$source] could not be found or is not readable. Skipping.</error>");
                continue;
            }

            // Check if target exists yet, create if not.
            if (! \is_dir($target_path)) {
                $this->mkdir($target_path);
            }

            // Now we know it exists, check we can write to it.
            if (! \is_writable($target_path)) {
                $this->output->writeln("<error>[$target_path] is not writable. Please check directory permissions.</error>");
                continue;
            }
            
            $this->deep_copy($source, $target_path);
        }
    }
1178331
public function getAll($source_directory, $target_directory, $mode = FTP_BINARY, $include_hidden = false)
    {
        $d = $this->scanDir($source_directory, false, $include_hidden);

        // do this for each file in the directory
        foreach ($d as $file) {
            $new_source_directory = $source_directory . '/' . $file['name'];
            $new_target_directory = $target_directory . '/' . $file['name'];
            if ($file['type'] == 'directory') {
                if (!is_dir($new_target_directory)) {
                    mkdir($new_target_directory);
                }
                $this->getAll($new_source_directory, $new_target_directory, $mode, $include_hidden);
            } else {
                $this->get($new_target_directory, $new_source_directory, $mode);
            }
        }

        return $this;
    }
143616
public function dumpFiles(Composer $composer, $paths, $targetDir = 'composer', $suffix = '', $staticPhpVersion = 70000)
	{
		$installationManager = $composer->getInstallationManager();
		$localRepo = $composer->getRepositoryManager()->getLocalRepository();
		$mainPackage = $composer->getPackage();
		$config = $composer->getConfig();

		$filesystem = new Filesystem();
		$filesystem->ensureDirectoryExists($config->get('vendor-dir'));
		// Do not remove double realpath() calls.
		// Fixes failing Windows realpath() implementation.
		// See https://bugs.php.net/bug.php?id=72738
		$basePath = $filesystem->normalizePath(realpath(realpath(getcwd())));
		$vendorPath = $filesystem->normalizePath(realpath(realpath($config->get('vendor-dir'))));
		$targetDir = $vendorPath.'/'.$targetDir;
		$filesystem->ensureDirectoryExists($targetDir);

		$vendorPathCode = $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true);
		$vendorPathCode52 = str_replace('__DIR__', 'dirname(__FILE__)', $vendorPathCode);
		$vendorPathToTargetDirCode = $filesystem->findShortestPathCode($vendorPath, realpath($targetDir), true);

		$appBaseDirCode = $filesystem->findShortestPathCode($vendorPath, $basePath, true);
		$appBaseDirCode = str_replace('__DIR__', '$vendorDir', $appBaseDirCode);

		// Collect information from all packages.
		$packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages());
		$autoloads = $this->parseAutoloads($packageMap, $mainPackage);

		if (!$suffix) {
			if (!$config->get('autoloader-suffix') && is_readable($vendorPath.'/autoload.php')) {
				$content = file_get_contents($vendorPath.'/autoload.php');
				if (preg_match('{ComposerAutoloaderInit([^:\s]+)::}', $content, $match)) {
					$suffix = $match[1];
				}
			}
			if (!$suffix) {
				$suffix = $config->get('autoloader-suffix') ?: md5(uniqid('', true));
			}
		}

		$paths = $this->parseAutoloadsTypeFiles($paths, $mainPackage);

		$autoloads['files'] = array_merge($paths, $autoloads['files']);

		$includeFilesFilePath = $targetDir.'/autoload_files.php';
		if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) {
			file_put_contents($includeFilesFilePath, $includeFilesFileContents);
		} elseif (file_exists($includeFilesFilePath)) {
			unlink($includeFilesFilePath);
		}
		file_put_contents($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath, $staticPhpVersion));
	}
471049
public function renderFile($content, $targetPath, array $options)
    {
        $options = $this->transformOptions($options);
        $pdfGenerator = $this->createPdfGenerator();

        $pdfGenerator->renderFileFromHtml(
            $content,
            $targetPath,
            $options
        );
    }
220275
public function actionIndex(array $sourceDirs, $targetDir)
    {
        $renderer = $this->findRenderer($this->template);
        $targetDir = $this->normalizeTargetDir($targetDir);
        if ($targetDir === false || $renderer === false) {
            return 1;
        }

        $renderer->apiUrl = './';
        $renderer->guidePrefix = $this->guidePrefix;

        if ($this->pageTitle !== null) {
            $renderer->pageTitle = $this->pageTitle;
        }

        // setup reference to guide
        if ($this->guide !== null) {
            $renderer->guideUrl = $guideUrl = $this->guide;
        } else {
            $guideUrl = './';
            $renderer->guideUrl = $targetDir;
            if (file_exists($renderer->generateGuideUrl('README.md'))) {
                $renderer->guideUrl = $guideUrl;
            } else {
                $renderer->guideUrl = null;
            }
        }

        // search for files to process
        if (($files = $this->searchFiles($sourceDirs)) === false) {
            return 1;
        }

        // load context from cache
        $context = $this->loadContext($targetDir);
        $this->stdout('Checking for updated files... ');
        foreach ($context->files as $file => $sha) {
            if (!file_exists($file)) {
                $this->stdout('At least one file has been removed. Rebuilding the context...');
                $context = new Context();
                if (($files = $this->searchFiles($sourceDirs)) === false) {
                    return 1;
                }
                break;
            }
            if (sha1_file($file) === $sha) {
                unset($files[$file]);
            }
        }
        $this->stdout('done.' . PHP_EOL, Console::FG_GREEN);

        // process files
        $fileCount = count($files);
        $this->stdout($fileCount . ' file' . ($fileCount == 1 ? '' : 's') . ' to update.' . PHP_EOL);
        Console::startProgress(0, $fileCount, 'Processing files... ', false);
        $done = 0;
        foreach ($files as $file) {
            $context->addFile($file);
            Console::updateProgress(++$done, $fileCount);
        }
        Console::endProgress(true);
        $this->stdout('done.' . PHP_EOL, Console::FG_GREEN);

        // save processed data to cache
        $this->storeContext($context, $targetDir);

        $this->updateContext($context);

        // render models
        $renderer->controller = $this;
        $renderer->render($context, $targetDir);

        if (!empty($context->errors)) {
            ArrayHelper::multisort($context->errors, 'file');
            file_put_contents($targetDir . '/errors.txt', print_r($context->errors, true));
            $this->stdout(count($context->errors) . " errors have been logged to $targetDir/errors.txt\n", Console::FG_RED, Console::BOLD);
        }

        if (!empty($context->warnings)) {
            ArrayHelper::multisort($context->warnings, 'file');
            file_put_contents($targetDir . '/warnings.txt', print_r($context->warnings, true));
            $this->stdout(count($context->warnings) . " warnings have been logged to $targetDir/warnings.txt\n", Console::FG_YELLOW, Console::BOLD);
        }

        return 0;
    }
398994
public function publishModule($module)
	{
		$this->amOnPage('administrator/index.php?option=com_modules');
		$this->searchForItem($module);
		$this->checkAllResults();
		$this->click(array('xpath' => "//div[@id='toolbar-publish']/button"));
		$this->waitForText(' published.', 30, array('id' => 'system-message-container'));
	}
808052
public function moveChildren($targetDir)
    {
        $info = new \SplFileInfo($targetDir);

        if (!$info->isDir())
        {
            throw new InvalidArgumentException(sprintf('Target dir not found'));
        }

        if (!$info->isReadable())
        {
            throw new InvalidArgumentException(sprintf('Target dir not readable'));
        }

        if (!$info->isWritable())
        {
            throw new InvalidArgumentException(sprintf('Target dir not writable'));
        }

        foreach (new \DirectoryIterator($this->dir) as $info)
        {
            if ($info->isDot())
            {
                continue;
            }

            $sourcePathname = $info->getPathname();
            $subdirPathname = $this->subtractBasedir($sourcePathname, $this->dir);
            $targetPathname = sprintf('%s/%s', $targetDir, $subdirPathname);
            rename($sourcePathname, $targetPathname);
        }
    }
1367434
public function moveFiles($source, $target, $files)
    {
        foreach ($files as $file) {
            $this->moveFile($source, $target, $files);
        }
    }