<?php
-/**
- * @file
- * Contains \DrupalComposer\DrupalScaffold\Handler.
- */
-
namespace DrupalComposer\DrupalScaffold;
+use Composer\Script\Event;
+use Composer\Installer\PackageEvent;
+use Composer\Plugin\CommandEvent;
use Composer\Composer;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\Util\RemoteFilesystem;
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
+/**
+ * Core class of the plugin, contains all logic which files should be fetched.
+ */
class Handler {
const PRE_DRUPAL_SCAFFOLD_CMD = 'pre-drupal-scaffold-cmd';
*/
protected $io;
+ /**
+ * @var bool
+ *
+ * A boolean indicating if progress should be displayed.
+ */
+ protected $progress;
+
/**
* @var \Composer\Package\PackageInterface
*/
/**
* Handler constructor.
*
- * @param Composer $composer
- * @param IOInterface $io
+ * @param \Composer\Composer $composer
+ * @param \Composer\IO\IOInterface $io
*/
public function __construct(Composer $composer, IOInterface $io) {
$this->composer = $composer;
$this->io = $io;
+ $this->progress = TRUE;
+
+ // Pre-load all of our sources so that we do not run up
+ // against problems in `composer update` operations.
+ $this->manualLoad();
+ }
+
+ protected function manualLoad() {
+ $src_dir = __DIR__;
+
+ $classes = [
+ 'CommandProvider',
+ 'DrupalScaffoldCommand',
+ 'FileFetcher',
+ 'PrestissimoFileFetcher',
+ ];
+
+ foreach ($classes as $src) {
+ if (!class_exists('\\DrupalComposer\\DrupalScaffold\\' . $src)) {
+ include "{$src_dir}/{$src}.php";
+ }
+ }
}
/**
return NULL;
}
+ /**
+ * Get the command options.
+ *
+ * @param \Composer\Plugin\CommandEvent $event
+ */
+ public function onCmdBeginsEvent(CommandEvent $event) {
+ if ($event->getInput()->hasOption('no-progress')) {
+ $this->progress = !($event->getInput()->getOption('no-progress'));
+ }
+ else {
+ $this->progress = TRUE;
+ }
+ }
+
/**
* Marks scaffolding to be processed after an install or update command.
*
* @param \Composer\Installer\PackageEvent $event
*/
- public function onPostPackageEvent(\Composer\Installer\PackageEvent $event){
+ public function onPostPackageEvent(PackageEvent $event) {
$package = $this->getCorePackage($event->getOperation());
if ($package) {
// By explicitly setting the core package, the onPostCmdEvent() will
*
* @param \Composer\Script\Event $event
*/
- public function onPostCmdEvent(\Composer\Script\Event $event) {
+ public function onPostCmdEvent(Event $event) {
// Only install the scaffolding if drupal/core was installed,
// AND there are no scaffolding files present.
if (isset($this->drupalCorePackage)) {
$remoteFs = new RemoteFilesystem($this->io);
- $fetcher = new PrestissimoFileFetcher($remoteFs, $options['source'], $files, $this->io, $this->composer->getConfig());
- $fetcher->fetch($version, $webroot);
+ $fetcher = new PrestissimoFileFetcher($remoteFs, $options['source'], $this->io, $this->progress, $this->composer->getConfig());
+ $fetcher->setFilenames(array_combine($files, $files));
+ $fetcher->fetch($version, $webroot, TRUE);
- $initialFileFetcher = new InitialFileFetcher($remoteFs, $options['source'], $this->getInitial());
- $initialFileFetcher->fetch($version, $webroot);
+ $fetcher->setFilenames($this->getInitial());
+ $fetcher->fetch($version, $webroot, FALSE);
// Call post-scaffold scripts.
$dispatcher->dispatch(self::POST_DRUPAL_SCAFFOLD_CMD);
* Look up the Drupal core package object, or return it from where we cached
* it in the $drupalCorePackage field.
*
- * @return PackageInterface
+ * @return \Composer\Package\PackageInterface
*/
public function getDrupalCorePackage() {
if (!isset($this->drupalCorePackage)) {
/**
* Retrieve the path to the web root.
*
- * @return string
+ * @return string
*/
public function getWebRoot() {
$drupalCorePackage = $this->getDrupalCorePackage();
* @param string $name
* Name of the package to get from the current composer installation.
*
- * @return PackageInterface
+ * @return \Composer\Package\PackageInterface
*/
protected function getPackage($name) {
return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*');
'excludes' => [],
'includes' => [],
'initial' => [],
- 'source' => 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}',
+ 'source' => 'https://cgit.drupalcode.org/drupal/plain/{path}?h={version}',
// Github: https://raw.githubusercontent.com/drupal/drupal/{version}/{path}
];
return $options;
/**
* Files from 8.3.x
*
- * @see http://cgit.drupalcode.org/drupal/tree/?h=8.3.x
+ * @see https://cgit.drupalcode.org/drupal/tree/?h=8.3.x
*/
$common = [
'.csslintrc',
'sites/example.settings.local.php',
'sites/example.sites.php',
'update.php',
- 'web.config'
+ 'web.config',
];
// Version specific variations.