ExpressiveInstaller\OptionalPackages::copyFile PHP Метод

copyFile() публичный статический Метод

Copy a file to its final destination in the skeleton.
public static copyFile ( Composer\IO\IOInterface $io, string $projectRoot, string $source, string $target, boolean $force = false )
$io Composer\IO\IOInterface
$projectRoot string
$source string Source file.
$target string Destination.
$force boolean whether or not to copy over an existing file.
    public static function copyFile(IOInterface $io, $projectRoot, $source, $target, $force = false)
    {
        // Copy file
        if ($force === false && is_file($projectRoot . $target)) {
            return;
        }
        $destinationPath = dirname($projectRoot . $target);
        if (!is_dir($destinationPath)) {
            mkdir($destinationPath, 0775, true);
        }
        $io->write(sprintf("  - Copying <info>%s</info>", $target));
        copy(__DIR__ . $source, $projectRoot . $target);
    }

Usage Example

 public function installPackage($config, $copyFilesKey)
 {
     /* TODO: First we need to set $composerDefinition, $composerRequires, $composerDevRequires and $stabilityFlags;
        // Add packages to install
        if (isset($config['packages'])) {
            foreach ($config['packages'] as $packageName) {
                OptionalPackages::addPackage($this->io, $packageName, $this->config['packages'][$packageName]);
            }
        }*/
     // Copy files
     if (isset($config[$copyFilesKey])) {
         foreach ($config[$copyFilesKey] as $source => $target) {
             OptionalPackages::copyFile($this->io->reveal(), $this->projectRoot, $source, $target);
         }
     }
 }