function AppendOp::existingFileHasData

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

Check to see if the append/prepend data has already been applied.

Parameters

string $contents: The contents of the target file.

\Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath $data_path: The path to the data to append or prepend

Return value

bool 'TRUE' if the append/prepend data already exists in contents.

1 call to AppendOp::existingFileHasData()
AppendOp::scaffoldAtNewLocation in composer/Plugin/Scaffold/Operations/AppendOp.php
Determines what to do if operation is used without a previous operation.

File

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

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 existingFileHasData($contents, $data_path) {
    if (empty($data_path)) {
        return FALSE;
    }
    $data = file_get_contents($data_path->fullPath());
    return str_contains($contents, $data);
}

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