function AppendOp::scaffoldAtNewLocation

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

Overrides AbstractOperation::scaffoldAtNewLocation

File

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

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 scaffoldAtNewLocation(ScaffoldFilePath $destination) {
    // If there is no existing scaffold file at the target location, then any
    // append we do will be to an unmanaged file.
    $this->managed = FALSE;
    // Default: do not allow an append over a file that was not scaffolded.
    if (!$this->forceAppend) {
        $message = "  - Skip <info>[dest-rel-path]</info>: cannot append to a path that was not scaffolded unless 'force-append' property is set.";
        return new SkipOp($message);
    }
    // If the target file does not exist, then we will allow the append to
    // happen if we have default data to provide for it.
    if (!file_exists($destination->fullPath())) {
        if (!empty($this->default)) {
            return $this;
        }
        $message = "  - Skip <info>[dest-rel-path]</info>: no file exists at the target path, and no default data provided.";
        return new SkipOp($message);
    }
    // If the target file DOES exist, and it already contains the append/prepend
    // data, then we will skip the operation.
    $existingData = file_get_contents($destination->fullPath());
    if ($this->existingFileHasData($existingData, $this->append) || $this->existingFileHasData($existingData, $this->prepend)) {
        $message = "  - Skip <info>[dest-rel-path]</info>: the file already has the append/prepend data.";
        return new SkipOp($message);
    }
    // Cache the original data to use during append.
    $this->originalContents = $existingData;
    return $this;
}

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