function ScaffoldFilePath::sourcePath

Same name in other branches
  1. 9 composer/Plugin/Scaffold/ScaffoldFilePath.php \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath::sourcePath()
  2. 8.9.x composer/Plugin/Scaffold/ScaffoldFilePath.php \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath::sourcePath()
  3. 11.x composer/Plugin/Scaffold/ScaffoldFilePath.php \Drupal\Composer\Plugin\Scaffold\ScaffoldFilePath::sourcePath()

Converts the relative source path into an absolute path.

The path returned will be relative to the package installation location.

Parameters

string $package_name: The name of the package containing the source file. Only used for error messages.

string $package_path: The installation path of the package containing the source file.

string $destination: Destination location provided as a relative path. Only used for error messages.

string $source: Source location provided as a relative path.

Return value

self Object wrapping the relative and absolute path to the source file.

3 calls to ScaffoldFilePath::sourcePath()
Fixtures::sourcePath in core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Fixtures.php
Gets a path to a source scaffold fixture.
OperationFactory::createAppendOp in composer/Plugin/Scaffold/Operations/OperationFactory.php
Creates an 'append' (or 'prepend') scaffold op.
OperationFactory::createReplaceOp in composer/Plugin/Scaffold/Operations/OperationFactory.php
Creates a 'replace' scaffold op.

File

composer/Plugin/Scaffold/ScaffoldFilePath.php, line 127

Class

ScaffoldFilePath
Manage the path to a file to scaffold.

Namespace

Drupal\Composer\Plugin\Scaffold

Code

public static function sourcePath($package_name, $package_path, $destination, $source) {
    // Complain if there is no source path.
    if (empty($source)) {
        throw new \RuntimeException("No scaffold file path given for {$destination} in package {$package_name}.");
    }
    // Calculate the full path to the source scaffold file.
    $source_full_path = $package_path . '/' . $source;
    if (!file_exists($source_full_path)) {
        throw new \RuntimeException("Scaffold file {$source} not found in package {$package_name}.");
    }
    if (is_dir($source_full_path)) {
        throw new \RuntimeException("Scaffold file {$source} in package {$package_name} is a directory; only files may be scaffolded.");
    }
    return new self('src', $package_name, $source, $source_full_path);
}

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