function AppendOp::process

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

Overrides OperationInterface::process

File

composer/Plugin/Scaffold/Operations/AppendOp.php, line 112

Class

AppendOp
Scaffold operation to add to the beginning and/or end of a scaffold file.

Namespace

Drupal\Composer\Plugin\Scaffold\Operations

Code

public function process(ScaffoldFilePath $destination, IOInterface $io, ScaffoldOptions $options) {
    $destination_path = $destination->fullPath();
    $interpolator = $destination->getInterpolator();
    // Be extra-noisy of creating a new file or appending to a non-scaffold
    // file. Note that if the file already has the append contents, then the
    // OperationFactory will make a SkipOp instead, and we will not get here.
    if (!$this->managed) {
        $message = '  - <info>NOTICE</info> Modifying existing file at <info>[dest-rel-path]</info>.';
        if (!file_exists($destination_path)) {
            $message = '  - <info>NOTICE</info> Creating a new file at <info>[dest-rel-path]</info>.';
        }
        $message .= ' Examine the contents and ensure that it came out correctly.';
        $io->write($interpolator->interpolate($message));
    }
    // Notify that we are prepending, if there is prepend data.
    if (!empty($this->prepend)) {
        $this->prepend
            ->addInterpolationData($interpolator, 'prepend');
        $io->write($interpolator->interpolate("  - Prepend to <info>[dest-rel-path]</info> from <info>[prepend-rel-path]</info>"));
    }
    // Notify that we are appending, if there is append data.
    if (!empty($this->append)) {
        $this->append
            ->addInterpolationData($interpolator, 'append');
        $io->write($interpolator->interpolate("  - Append to <info>[dest-rel-path]</info> from <info>[append-rel-path]</info>"));
    }
    // Write the resulting data
    file_put_contents($destination_path, $this->contents());
    // Return a ScaffoldResult with knowledge of whether this file is managed.
    return new ScaffoldResult($destination, $this->managed);
}

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