AppendOp example

$fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $options = ScaffoldOptions::create([]);
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());

    // Create a file.     file_put_contents($destination->fullPath(), "# This is a test\n");

    $prepend = $fixtures->sourcePath('drupal-drupal-test-append', 'prepend-to-robots.txt');
    $append = $fixtures->sourcePath('drupal-drupal-test-append', 'append-to-robots.txt');
    $sut = new AppendOp($prepend$append, TRUE);
    $sut->scaffoldAtNewLocation($destination);

    $expected = <<<EOT # robots.txt fixture scaffolded from "file-mappings" in drupal-drupal-test-append composer.json fixture. # This content is prepended to the top of the existing robots.txt fixture. # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # This is a test # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # This content is appended to the bottom of the existing robots.txt fixture. # robots.txt fixture scaffolded from "file-mappings" in drupal-drupal-test-append composer.json fixture.

  public function appendOp($project_name$source) {
    $source_path = $this->sourcePath($project_name$source);
    return new AppendOp(NULL, $source_path);
  }

  /** * Gets a destination path in a tmp dir. * * Use in place of ScaffoldFilePath::destinationPath(). * * @param string $destination * Destination path; should be in the form '[web-root]/robots.txt', where * '[web-root]' is always literally '[web-root]', with any arbitrarily * desired filename following. * @param \Drupal\Composer\Plugin\Scaffold\Interpolator $interpolator * Location replacements. Obtain via Fixtures::getLocationReplacements() * when creating multiple scaffold destinations. * @param string $package_name * (optional) The name of the fixture package that this path came from. * Taken from interpolator if not provided. * * @return \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath * A destination scaffold file backed by temporary storage. * * @see \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath::destinationPath() */
if ($operation_data->hasAppend()) {
      $append_source_file = ScaffoldFilePath::sourcePath($package_name$package_path$operation_data->destination()$operation_data->append());
    }
    if ($operation_data->hasDefault()) {
      $default_data_file = ScaffoldFilePath::sourcePath($package_name$package_path$operation_data->destination()$operation_data->default());
    }
    if (!$this->hasContent($prepend_source_file) && !$this->hasContent($append_source_file)) {
      $message = ' - Keep <info>[dest-rel-path]</info> unchanged: no content to prepend / append was provided.';
      return new SkipOp($message);
    }

    return new AppendOp($prepend_source_file$append_source_file$operation_data->forceAppend()$default_data_file);
  }

  /** * Checks to see if the specified scaffold file exists and has content. * * @param \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath $file * Scaffold file to check. * * @return bool * True if the file exists and has content. */
  
Home | Imprint | This part of the site doesn't use cookies.