Issue #2982684 by greg.1.anderson, Mile23, Mixologic, webflo, alexpott, yogeshmpawar, pingwin4eg, vijaycs85, larowlan, dww, borisson_, phenaproxima, kim.pepper, bojanz, grasmash, hctom, kmbremner, pingers, Jax, sherakama, derhasi, claudiu.cristea, jhedstrom, Xano, Grimreaper: Add a composer scaffolding plugin to core
2019-07-10 21:47:33 +00:00
|
|
|
<?php
|
|
|
|
|
2019-08-22 02:45:53 +00:00
|
|
|
namespace Drupal\Composer\Plugin\Scaffold;
|
Issue #2982684 by greg.1.anderson, Mile23, Mixologic, webflo, alexpott, yogeshmpawar, pingwin4eg, vijaycs85, larowlan, dww, borisson_, phenaproxima, kim.pepper, bojanz, grasmash, hctom, kmbremner, pingers, Jax, sherakama, derhasi, claudiu.cristea, jhedstrom, Xano, Grimreaper: Add a composer scaffolding plugin to core
2019-07-10 21:47:33 +00:00
|
|
|
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
use Composer\Util\Filesystem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Per-project options from the 'extras' section of the composer.json file.
|
|
|
|
*
|
|
|
|
* Projects that describe scaffold files do so via their scaffold options.
|
2019-10-08 21:20:58 +00:00
|
|
|
* This data is pulled from the 'drupal-scaffold' portion of the extras
|
Issue #2982684 by greg.1.anderson, Mile23, Mixologic, webflo, alexpott, yogeshmpawar, pingwin4eg, vijaycs85, larowlan, dww, borisson_, phenaproxima, kim.pepper, bojanz, grasmash, hctom, kmbremner, pingers, Jax, sherakama, derhasi, claudiu.cristea, jhedstrom, Xano, Grimreaper: Add a composer scaffolding plugin to core
2019-07-10 21:47:33 +00:00
|
|
|
* section of the project data.
|
2020-02-21 09:34:07 +00:00
|
|
|
*
|
|
|
|
* @internal
|
Issue #2982684 by greg.1.anderson, Mile23, Mixologic, webflo, alexpott, yogeshmpawar, pingwin4eg, vijaycs85, larowlan, dww, borisson_, phenaproxima, kim.pepper, bojanz, grasmash, hctom, kmbremner, pingers, Jax, sherakama, derhasi, claudiu.cristea, jhedstrom, Xano, Grimreaper: Add a composer scaffolding plugin to core
2019-07-10 21:47:33 +00:00
|
|
|
*/
|
|
|
|
class ManageOptions {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Composer service.
|
|
|
|
*
|
|
|
|
* @var \Composer\Composer
|
|
|
|
*/
|
|
|
|
protected $composer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ManageOptions constructor.
|
|
|
|
*
|
|
|
|
* @param \Composer\Composer $composer
|
|
|
|
* The Composer service.
|
|
|
|
*/
|
|
|
|
public function __construct(Composer $composer) {
|
|
|
|
$this->composer = $composer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the root-level scaffold options for this project.
|
|
|
|
*
|
2019-08-22 02:45:53 +00:00
|
|
|
* @return \Drupal\Composer\Plugin\Scaffold\ScaffoldOptions
|
Issue #2982684 by greg.1.anderson, Mile23, Mixologic, webflo, alexpott, yogeshmpawar, pingwin4eg, vijaycs85, larowlan, dww, borisson_, phenaproxima, kim.pepper, bojanz, grasmash, hctom, kmbremner, pingers, Jax, sherakama, derhasi, claudiu.cristea, jhedstrom, Xano, Grimreaper: Add a composer scaffolding plugin to core
2019-07-10 21:47:33 +00:00
|
|
|
* The scaffold options object.
|
|
|
|
*/
|
|
|
|
public function getOptions() {
|
|
|
|
return $this->packageOptions($this->composer->getPackage());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the scaffold options for the stipulated project.
|
|
|
|
*
|
|
|
|
* @param \Composer\Package\PackageInterface $package
|
|
|
|
* The package to fetch the scaffold options from.
|
|
|
|
*
|
2019-08-22 02:45:53 +00:00
|
|
|
* @return \Drupal\Composer\Plugin\Scaffold\ScaffoldOptions
|
Issue #2982684 by greg.1.anderson, Mile23, Mixologic, webflo, alexpott, yogeshmpawar, pingwin4eg, vijaycs85, larowlan, dww, borisson_, phenaproxima, kim.pepper, bojanz, grasmash, hctom, kmbremner, pingers, Jax, sherakama, derhasi, claudiu.cristea, jhedstrom, Xano, Grimreaper: Add a composer scaffolding plugin to core
2019-07-10 21:47:33 +00:00
|
|
|
* The scaffold options object.
|
|
|
|
*/
|
|
|
|
public function packageOptions(PackageInterface $package) {
|
|
|
|
return ScaffoldOptions::create($package->getExtra());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an interpolator for the 'locations' element.
|
|
|
|
*
|
|
|
|
* The interpolator returned will replace a path string with the tokens
|
|
|
|
* defined in the 'locations' element.
|
|
|
|
*
|
|
|
|
* Note that only the root package may define locations.
|
|
|
|
*
|
2019-08-22 02:45:53 +00:00
|
|
|
* @return \Drupal\Composer\Plugin\Scaffold\Interpolator
|
Issue #2982684 by greg.1.anderson, Mile23, Mixologic, webflo, alexpott, yogeshmpawar, pingwin4eg, vijaycs85, larowlan, dww, borisson_, phenaproxima, kim.pepper, bojanz, grasmash, hctom, kmbremner, pingers, Jax, sherakama, derhasi, claudiu.cristea, jhedstrom, Xano, Grimreaper: Add a composer scaffolding plugin to core
2019-07-10 21:47:33 +00:00
|
|
|
* Interpolator that will do replacements in a string using tokens in
|
|
|
|
* 'locations' element.
|
|
|
|
*/
|
|
|
|
public function getLocationReplacements() {
|
|
|
|
return (new Interpolator())->setData($this->ensureLocations());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that all of the locations defined in the scaffold files exist.
|
|
|
|
*
|
|
|
|
* Create them on the filesystem if they do not.
|
|
|
|
*/
|
|
|
|
protected function ensureLocations() {
|
|
|
|
$fs = new Filesystem();
|
|
|
|
$locations = $this->getOptions()->locations() + ['web_root' => './'];
|
|
|
|
$locations = array_map(function ($location) use ($fs) {
|
|
|
|
$fs->ensureDirectoryExists($location);
|
|
|
|
$location = realpath($location);
|
|
|
|
return $location;
|
|
|
|
}, $locations);
|
|
|
|
return $locations;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|