You are here

protected function AppendOp::generateContents in Drupal 9

Same name and namespace in other branches
  1. 8 composer/Plugin/Scaffold/Operations/AppendOp.php \Drupal\Composer\Plugin\Scaffold\Operations\AppendOp::generateContents()

Load the scaffold contents or otherwise generate what is needed.

Return value

string The contents of the scaffold file.

Overrides AbstractOperation::generateContents

File

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

Class

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

Namespace

Drupal\Composer\Plugin\Scaffold\Operations

Code

protected function generateContents() {

  // Fetch the prepend contents, if provided.
  $prepend_contents = '';
  if (!empty($this->prepend)) {
    $prepend_contents = file_get_contents($this->prepend
      ->fullPath()) . "\n";
  }

  // Fetch the append contents, if provided.
  $append_contents = '';
  if (!empty($this->append)) {
    $append_contents = "\n" . file_get_contents($this->append
      ->fullPath());
  }

  // Get the original contents, or the default data if the original is empty.
  $original_contents = $this->originalContents;
  if (empty($original_contents) && !empty($this->default)) {
    $original_contents = file_get_contents($this->default
      ->fullPath());
  }

  // Attach it all together.
  return $prepend_contents . $original_contents . $append_contents;
}