Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
fixed #35
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Aug 9, 2018
1 parent a3d1b56 commit 3d002dc
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 1,559 deletions.
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ parameters:

ignoreErrors:
# QuestionInstallationManager
- '#Call to an undefined method Composer\\Installer\\InstallationManager::getOperations#'
- '#\$package of method Composer\\Package\\Version\\VersionSelector\:\:findRecommendedRequireVersion\(\) expects Composer\\Package\\PackageInterface, Composer\\Package\\PackageInterface\|true given#'
# ScriptExecutor
- '#Call to static method cerebroBinary\(\) on an unknown class Viserio\\Component\\Console\\Application#'
Expand Down
33 changes: 2 additions & 31 deletions src/Automatic/Automatic.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
use Composer\Script\ScriptEvents;
use FilesystemIterator;
use Narrowspark\Automatic\Common\Contract\Package as PackageContract;
use Narrowspark\Automatic\Common\Package;
use Narrowspark\Automatic\Common\Traits\ExpandTargetDirTrait;
use Narrowspark\Automatic\Common\Traits\GetGenericPropertyReaderTrait;
use Narrowspark\Automatic\Common\Util;
use Narrowspark\Automatic\Installer\ConfiguratorInstaller;
use Narrowspark\Automatic\Installer\QuestionInstallationManager;
use Narrowspark\Automatic\Installer\SkeletonInstaller;
use Narrowspark\Automatic\Prefetcher\ParallelDownloader;
use Narrowspark\Automatic\Prefetcher\Prefetcher;
Expand Down Expand Up @@ -269,7 +267,7 @@ public function onPostCreateProject(Event $event): void
$manipulator->removeProperty('description');

foreach ($this->container->get('composer-extra') as $key => $value) {
if ($key !== Util::AUTOMATIC) {
if ($key !== Util::COMPOSER_EXTRA_KEY) {
$manipulator->addSubNode('extra', $key, $value);
}
}
Expand Down Expand Up @@ -309,7 +307,7 @@ public function onPostUpdate(Event $event, array $operations = []): void
$this->operations = $operations;
}

$automaticOptions = $this->container->get('composer-extra')[Util::AUTOMATIC];
$automaticOptions = $this->container->get('composer-extra')[Util::COMPOSER_EXTRA_KEY];
$allowInstall = $automaticOptions['allow-auto-install'] ?? false;
$packages = $this->container->get(OperationsResolver::class)->resolve($this->operations);
$lock = $this->container->get(Lock::class);
Expand Down Expand Up @@ -646,17 +644,6 @@ private function doInstall(PackageContract $package, PackageConfigurator $packag
$this->container->get(Configurator::class)->configure($package);
$packageConfigurator->configure($package);

if ($package->hasConfig(QuestionInstallationManager::TYPE)) {
/** @var \Narrowspark\Automatic\Installer\QuestionInstallationManager $questionInstallationManager */
$questionInstallationManager = $this->container->get(QuestionInstallationManager::class);

foreach ($questionInstallationManager->install($package, (array) $package->getConfig(QuestionInstallationManager::TYPE)) as $operation) {
$this->doInstall($operation, $packageConfigurator);
}

$package->setSelectedQuestionableRequirements($questionInstallationManager->getSelectedPackages());
}

if ($package->hasConfig('post-install-output')) {
foreach ((array) $package->getConfig('post-install-output') as $line) {
$this->postInstallOutput[] = self::expandTargetDir($this->container->get('composer-extra'), $line);
Expand Down Expand Up @@ -686,22 +673,6 @@ private function doUninstall(PackageContract $package, PackageConfigurator $pack
/** @var \Narrowspark\Automatic\Lock $lock */
$lock = $this->container->get(Lock::class);

if ($package->hasConfig(QuestionInstallationManager::TYPE)) {
$questionableRequirements = [];

foreach ((array) $lock->get(self::LOCK_PACKAGES) as $packageName => $data) {
$lockPackage = Package::createFromLock($packageName, $data);

if ($lockPackage->isQuestionableRequirement() && $lockPackage->getParentName() === $package->getName()) {
$questionableRequirements[] = $lockPackage;
}
}

foreach ($this->container->get(QuestionInstallationManager::class)->uninstall($package, $questionableRequirements) as $operation) {
$this->doUninstall($operation, $packageConfigurator);
}
}

$lock->remove($package->getName());
}

Expand Down
11 changes: 1 addition & 10 deletions src/Automatic/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Narrowspark\Automatic\Common\Util;
use Narrowspark\Automatic\Installer\ConfiguratorInstaller;
use Narrowspark\Automatic\Installer\InstallationManager;
use Narrowspark\Automatic\Installer\QuestionInstallationManager;
use Narrowspark\Automatic\Installer\SkeletonInstaller;
use Narrowspark\Automatic\Prefetcher\ParallelDownloader;
use Narrowspark\Automatic\Prefetcher\Prefetcher;
Expand Down Expand Up @@ -63,7 +62,7 @@ public function __construct(Composer $composer, IOInterface $io)
'composer-extra' => static function (Container $container) {
return \array_merge(
[
Util::AUTOMATIC => [
Util::COMPOSER_EXTRA_KEY => [
'allow-auto-install' => false,
'dont-discover' => [],
],
Expand Down Expand Up @@ -113,14 +112,6 @@ public function __construct(Composer $composer, IOInterface $io)
$container->get(InputInterface::class)
);
},
QuestionInstallationManager::class => static function (Container $container) {
return new QuestionInstallationManager(
$container->get(Composer::class),
$container->get(IOInterface::class),
$container->get(InputInterface::class),
$container->get(OperationsResolver::class)
);
},
RemoteFilesystem::class => static function (Container $container) {
return Factory::createRemoteFilesystem(
$container->get(IOInterface::class),
Expand Down
22 changes: 17 additions & 5 deletions src/Automatic/Installer/InstallationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ protected function preparePackagesToInstall(array $requires, array $rootPackages
continue;
}

// Check if package is currently installed, if so, use installed constraint and skip question.
if (isset($this->installedPackages[$packageName])) {
$version = $this->installedPackages[$packageName];
$constraint = \mb_strpos($version, 'dev-') === false ? '^' . $version : $version;
// Check if package is currently installed, if so, use installed constraint.
if (isset($toInstall[$packageName])) {
$version = $toInstall[$packageName];
$constraint = \mb_strpos($version, 'dev') === false ? '^' . $version : $version;

$toInstall[$packageName] = $constraint;

Expand All @@ -140,7 +140,19 @@ protected function preparePackagesToInstall(array $requires, array $rootPackages
}

if (\in_array($version, ['*', null, ''], true)) {
$constraint = $this->findVersion($packageName);
$constraint = $this->io->askAndValidate(
\sprintf(
'Enter the version of <info>%s</info> to require (or leave blank to use the latest version): ',
$packageName
),
function ($input) {
return \trim($input) ?? false;
}
);

if ($constraint === false) {
$constraint = $this->findBestVersionForPackage($packageName);
}
} else {
$constraint = $version;
}
Expand Down
Loading

0 comments on commit 3d002dc

Please sign in to comment.