You are here

protected function OperationData::convertScaffoldMetadata in Drupal 9

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

Performs the conversion-to-array step in normalizeScaffoldMetadata.

Parameters

string $destination: The destination path for the scaffold file.

mixed $value: The metadata for this operation object, which varies by operation type.

Return value

array Normalized scaffold metadata.

1 call to OperationData::convertScaffoldMetadata()
OperationData::normalizeScaffoldMetadata in composer/Plugin/Scaffold/Operations/OperationData.php
Normalizes metadata by converting literal values into arrays.

File

composer/Plugin/Scaffold/Operations/OperationData.php, line 206

Class

OperationData
Holds parameter data for operation objects during operation creation only.

Namespace

Drupal\Composer\Plugin\Scaffold\Operations

Code

protected function convertScaffoldMetadata($destination, $value) {
  if (is_bool($value)) {
    if (!$value) {
      return [
        self::MODE => SkipOp::ID,
      ];
    }
    throw new \RuntimeException("File mapping {$destination} cannot be given the value 'true'.");
  }
  if (empty($value)) {
    throw new \RuntimeException("File mapping {$destination} cannot be empty.");
  }
  if (is_string($value)) {
    $value = [
      self::PATH => $value,
    ];
  }

  // If there is no 'mode', but there is an 'append' or a 'prepend' path,
  // then the mode is 'append' (append + prepend).
  if (!isset($value[self::MODE]) && (isset($value[self::APPEND]) || isset($value[self::PREPEND]))) {
    $value[self::MODE] = AppendOp::ID;
  }
  return $value;
}