저자: Bryan Davis (bd808@bd808.com)
 /**
  * Merge extra config into a RootPackageInterface
  *
  * @param RootPackageInterface $root
  * @param PluginState $state
  */
 public function mergeExtra(RootPackageInterface $root, PluginState $state)
 {
     $extra = $this->package->getExtra();
     unset($extra['merge-plugin']);
     if (!$state->shouldMergeExtra() || empty($extra)) {
         return;
     }
     $rootExtra = $root->getExtra();
     $unwrapped = self::unwrapIfNeeded($root, 'setExtra');
     if ($state->replaceDuplicateLinks()) {
         $unwrapped->setExtra(self::mergeExtraArray($state->shouldMergeExtraDeep(), $rootExtra, $extra));
     } else {
         if (!$state->shouldMergeExtraDeep()) {
             foreach (array_intersect(array_keys($extra), array_keys($rootExtra)) as $key) {
                 $this->logger->info("Ignoring duplicate <comment>{$key}</comment> in " . "<comment>{$this->path}</comment> extra config.");
             }
         }
         $unwrapped->setExtra(self::mergeExtraArray($state->shouldMergeExtraDeep(), $extra, $rootExtra));
     }
 }
예제 #2
0
 /**
  * Handle an event callback following an install or update command. If our
  * plugin was installed during the run then trigger an update command to
  * process any merge-patterns in the current config.
  *
  * @param Event $event
  */
 public function onPostInstallOrUpdate(Event $event)
 {
     // @codeCoverageIgnoreStart
     if ($this->state->isFirstInstall()) {
         $this->state->setFirstInstall(false);
         $this->logger->info('<comment>' . 'Running additional update to apply merge settings' . '</comment>');
         $config = $this->composer->getConfig();
         $preferSource = $config->get('preferred-install') == 'source';
         $preferDist = $config->get('preferred-install') == 'dist';
         $installer = Installer::create($event->getIO(), Factory::create($event->getIO(), null, false));
         $installer->setPreferSource($preferSource);
         $installer->setPreferDist($preferDist);
         $installer->setDevMode($event->isDevMode());
         $installer->setDumpAutoloader($this->state->shouldDumpAutoloader());
         $installer->setOptimizeAutoloader($this->state->shouldOptimizeAutoloader());
         if ($this->state->forceUpdate()) {
             // Force update mode so that new packages are processed rather
             // than just telling the user that composer.json and
             // composer.lock don't match.
             $installer->setUpdate(true);
         }
         $installer->run();
     }
     // @codeCoverageIgnoreEnd
 }
 /**
  * Merge extra config into a RootPackage
  *
  * @param RootPackage $root
  * @param PluginState $state
  */
 public function mergeExtra(RootPackage $root, PluginState $state)
 {
     $extra = $this->package->getExtra();
     unset($extra['merge-plugin']);
     if (!$state->shouldMergeExtra() || empty($extra)) {
         return;
     }
     $rootExtra = $root->getExtra();
     if ($state->replaceDuplicateLinks()) {
         $root->setExtra(array_merge($rootExtra, $extra));
     } else {
         foreach ($extra as $key => $value) {
             if (isset($rootExtra[$key])) {
                 $this->logger->debug("Ignoring duplicate <comment>{$key}</comment> in " . "<comment>{$this->path}</comment> extra config.");
             }
         }
         $root->setExtra(array_merge($extra, $rootExtra));
     }
 }