SkipOp example

$destination = ScaffoldFilePath::destinationPath($package_name$destination_rel_path$location_replacements);

        // If there was already a scaffolding operation happening at this path,         // allow the new operation to decide how to handle the override.         // Usually, the new operation will replace whatever was there before.         if (isset($scaffoldFiles[$destination_rel_path])) {
          $previous_scaffold_file = $scaffoldFiles[$destination_rel_path];
          $op = $op->scaffoldOverExistingTarget($previous_scaffold_file->op());

          // Remove the previous op so we only touch the destination once.           $message = " - Skip <info>[dest-rel-path]</info>: overridden in <comment>{$package_name}</comment>";
          $this->scaffoldFilesByProject[$previous_scaffold_file->packageName()][$destination_rel_path] = new ScaffoldFileInfo($destinationnew SkipOp($message));
        }
        // If there is NOT already a scaffolding operation happening at this         // path, notify the scaffold operation of this fact.         else {
          $op = $op->scaffoldAtNewLocation($destination);
        }

        // Combine the scaffold operation with the destination and record it.         $scaffold_file = new ScaffoldFileInfo($destination$op);
        $scaffoldFiles[$destination_rel_path] = $scaffold_file;
        $this->scaffoldFilesByProject[$package_name][$destination_rel_path] = $scaffold_file;
      }
/** * {@inheritdoc} */
  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);
    }

    

class SkipOpTest extends TestCase {
  use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $options = ScaffoldOptions::create([]);
    $sut = new SkipOp();
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());
    // Test the system under test.     $sut->process($destination$fixtures->io()$options);
    // Assert that the target file was not created.     $this->assertFileDoesNotExist($destination->fullPath());
    // Confirm that expected output was written to our io fixture.     $output = $fixtures->getOutput();
    $this->assertStringContainsString('Skip [web-root]/robots.txt: disabled', $output);
  }

}

  public function create(PackageInterface $package, OperationData $operation_data) {
    switch ($operation_data->mode()) {
      case SkipOp::ID:
        return new SkipOp();

      case ReplaceOp::ID:
        return $this->createReplaceOp($package$operation_data);

      case AppendOp::ID:
        return $this->createAppendOp($package$operation_data);
    }
    throw new \RuntimeException("Unknown scaffold operation mode <comment>{$operation_data->mode()}</comment>.");
  }

  /** * Creates a 'replace' scaffold op. * * Replace ops may copy or symlink, depending on settings. * * @param \Composer\Package\PackageInterface $package * The package that relative paths will be relative from. * @param OperationData $operation_data * The parameter data for this operation object, i.e. the relative 'path'. * * @return \Drupal\Composer\Plugin\Scaffold\Operations\OperationInterface * A scaffold replace operation object. */
$scaffold_file_fixtures = [
      'fixtures/drupal-assets-fixture' => [
        '[web-root]/index.php' => $fixtures->replaceOp('drupal-assets-fixture', 'index.php'),
        '[web-root]/.htaccess' => $fixtures->replaceOp('drupal-assets-fixture', '.htaccess'),
        '[web-root]/robots.txt' => $fixtures->replaceOp('drupal-assets-fixture', 'robots.txt'),
        '[web-root]/sites/default/default.services.yml' => $fixtures->replaceOp('drupal-assets-fixture', 'default.services.yml'),
      ],
      'fixtures/drupal-profile' => [
        '[web-root]/sites/default/default.services.yml' => $fixtures->replaceOp('drupal-profile', 'profile.default.services.yml'),
      ],
      'fixtures/drupal-drupal' => [
        '[web-root]/.htaccess' => new SkipOp(),
        '[web-root]/robots.txt' => $fixtures->appendOp('drupal-drupal-test-append', 'append-to-robots.txt'),
      ],
    ];
    $sut = new ScaffoldFileCollection($scaffold_file_fixtures$locationReplacements);
    $resolved_file_mappings = iterator_to_array($sut);
    // Confirm that the keys of the output are the same as the keys of the     // input.     $this->assertEquals(array_keys($scaffold_file_fixtures)array_keys($resolved_file_mappings));
    // '[web-root]/robots.txt' is now a SkipOp, as it is now part of an     // append operation.     $this->assertEquals([
      
Home | Imprint | This part of the site doesn't use cookies.