function ReplaceOp::process

Same name in other branches
  1. 9 composer/Plugin/Scaffold/Operations/ReplaceOp.php \Drupal\Composer\Plugin\Scaffold\Operations\ReplaceOp::process()
  2. 10 composer/Plugin/Scaffold/Operations/ReplaceOp.php \Drupal\Composer\Plugin\Scaffold\Operations\ReplaceOp::process()
  3. 11.x composer/Plugin/Scaffold/Operations/ReplaceOp.php \Drupal\Composer\Plugin\Scaffold\Operations\ReplaceOp::process()

Overrides OperationInterface::process

File

composer/Plugin/Scaffold/Operations/ReplaceOp.php, line 60

Class

ReplaceOp
Scaffold operation to copy or symlink from source to destination.

Namespace

Drupal\Composer\Plugin\Scaffold\Operations

Code

public function process(ScaffoldFilePath $destination, IOInterface $io, ScaffoldOptions $options) {
    $fs = new Filesystem();
    $destination_path = $destination->fullPath();
    // Do nothing if overwrite is 'false' and a file already exists at the
    // destination.
    if ($this->overwrite === FALSE && file_exists($destination_path)) {
        $interpolator = $destination->getInterpolator();
        $io->write($interpolator->interpolate("  - Skip <info>[dest-rel-path]</info> because it already exists and overwrite is <comment>false</comment>."));
        return new ScaffoldResult($destination, FALSE);
    }
    // Get rid of the destination if it exists, and make sure that
    // the directory where it's going to be placed exists.
    $fs->remove($destination_path);
    $fs->ensureDirectoryExists(dirname($destination_path));
    if ($options->symlink()) {
        return $this->symlinkScaffold($destination, $io);
    }
    return $this->copyScaffold($destination, $io);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.