Merge extra config into a RootPackageInterface

@param RootPackageInterface $root
@param PluginState $state
9918
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)
            );
        }
    }
71415
protected function mergeAutoload($type, RootPackageInterface $root)
    {
        $getter = 'get' . ucfirst($type);
        $setter = 'set' . ucfirst($type);

        $autoload = $this->package->{$getter}();
        if (empty($autoload)) {
            return;
        }

        $unwrapped = self::unwrapIfNeeded($root, $setter);
        $unwrapped->{$setter}(array_merge_recursive(
            $root->{$getter}(),
            $this->fixRelativePaths($autoload)
        ));
    }
408308
protected function mergeRequires(RootPackageInterface $root, PluginState $state)
    {
        if ( ! empty($requires = $this->getPackage()->getRequires())) {
            $this->mergeStabilityFlags($root, $requires);

            $duplicateLinks = [];
            $requires       = $this->replaceSelfVersionDependencies(
                'require', $requires, $root
            );

            $root->setRequires($this->mergeLinks(
                $root->getRequires(), $requires, $state, $duplicateLinks
            ));

            $state->addDuplicateLinks('require', $duplicateLinks);
        }
    }
140720
public static function activate_state($state)
    {
        foreach (self::variants() as $variant => $instance) {
            if (isset($state[$variant]) && $instance->appliesToEnvironment()) {
                $instance->activateState($state[$variant]);
            }
        }
    }
961358
public static function writeConfigFile($configFile, $plugins, $root = null)
    {
        $root = $root ?: dirname(dirname($configFile));

        $data = [];
        foreach ($plugins as $name => $pluginPath) {
            // Normalize to *nix paths.
            $pluginPath = str_replace('\\', '/', $pluginPath);
            $pluginPath .= '/';

            $pluginPath = str_replace(
                DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR,
                DIRECTORY_SEPARATOR,
                $pluginPath
            );

            // Namespaced plugins should use /
            $name = str_replace('\\', '/', $name);

            $data[] = sprintf("        '%s' => '%s'", $name, $pluginPath);
        }

        $data = implode(",\n", $data);

        $contents = <<<'PHP'
<?php
$baseDir = dirname(dirname(__file__));
return [
    'plugins' => [
%s
    ]
];
PHP;
        $contents = sprintf($contents, $data);

        // Gross hacks to work around composer smashing `__FILE__` in this
        // PHP file when it runs the code through eval()
        $uppercase = function ($matches) {
            return strtoupper($matches[0]);
        };
        $contents = preg_replace_callback('/__file__/', $uppercase, $contents);

        $root = str_replace(
            DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR,
            DIRECTORY_SEPARATOR,
            $root
        );

        // Normalize to *nix paths.
        $root = str_replace('\\', '/', $root);
        $contents = str_replace('\'' . $root, '$baseDir . \'', $contents);

        file_put_contents($configFile, $contents);
    }
584430
protected function mergeStabilityFlags(
        RootPackageInterface $root,
        array $requires
    ) {
        $flags = $root->getStabilityFlags();
        $sf = new StabilityFlags($flags, $root->getMinimumStability());

        $unwrapped = self::unwrapIfNeeded($root, 'setStabilityFlags');
        $unwrapped->setStabilityFlags(array_merge(
            $flags,
            $sf->extractAll($requires)
        ));
    }
868180
protected function _setState($state)
    {
        if ($state !== null && !($state instanceof MapInterface)) {
            throw $this->_createInvalidArgumentException(
                $this->__('Argument is not a valid map'), null, null, $state
            );
        }

        $this->state = $state;
    }
721865
protected static function mergeCommandOptionsIntoConfiguration(Configuration $config, InputExtendedInterface $input)
    {
        $configurationMapping = [
            // Database credentials
            'database-host' => 'Database.Host',
            'database-user' => 'Database.Username',
            'database-pass' => 'Database.Password',
            'database-port' => 'Database.Port',
            'database-name' => 'Database.Name',
            // SSH settings
            'ssh-key'       => 'SSH.KeyFile',
        ];

        foreach ($configurationMapping as $optionName => $configName) {
            if ($input->isOptionSet($optionName) === true) {
                $config->setConfigurationValue($configName, $input->getOption($optionName));

            // If the value is not set / available, set this to nothing
            } elseif (!$config->getConfigurationValue($configName)) {
                $config->setConfigurationValue($configName, null);
            }
        }

        return $config;
    }
371703
private function saveJobState(JobConfigurationInterface $configuration, $state)
    {
        $configuration->setState($state);
        $this->configurationManager->add($configuration, true);
        
        $this->eventDispatcher->dispatch(JobQueueEvents::CHANGE_JOB_STATE, new JobEvent($configuration));
    }
822709
protected static function collapseDotFolder($root, $part, &$canonicalParts)
    {
        if ('.' === $part) {
            return;
        }
        // Collapse ".." with the previous part, if one exists
        // Don't collapse ".." if the previous part is also ".."
        if ('..' === $part && count($canonicalParts) > 0
            && '..' !== $canonicalParts[count($canonicalParts) - 1]
        ) {
            array_pop($canonicalParts);
            return;
        }
        // Only add ".." prefixes for relative paths
        if ('..' !== $part || '' === $root) {
            $canonicalParts[] = $part;
        }
    }
822864
public function put(StateInterface $state): self
    {
        $cloned_map = clone $this;
        $cloned_map->internal_map->put($state->getName(), $state);
        return $cloned_map;
    }
926529
public function setState($state)
    {
        $state = (int) $state;
        if ($this->isRoot() && !($state & Page::STATE_ONLINE)) {
            throw new \LogicException("Root page state must be online.");
        }

        if (!$this->isOnline() && (self::STATE_ONLINE & $state) && !$this->isRoot() && !$this->getPublishing()) {
            $this->setPublishing(new \DateTime());
        }

        $this->_state = $state;

        return $this;
    }
1112963
public static function registerIncludeRoot($root=null)
  {
    if(is_null($root)){
      $root = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR;
    }
    if(!in_array($root, self::$frameworkRoots)){
      self::$frameworkRoots[] = $root;
      return true;
    }
    return false;
  }
488883
public function showPackage($target, $package = '', $version = '', $root = false)
    {
        return $this->app['extend.action']['show']->execute($target, $package, $version, $root);
    }
892192
public static function buildDI($root, bool $resolveEnvironment = false)
    {
        $root = rtrim($root, '/');

        $container = new ContainerBuilder;

        $loader = static::buildConfigLoader($container, [$root]);

        if (class_exists(Configuration::class) && class_exists(RuntimeInstantiator::class)) {
            $container->setProxyInstantiator(new RuntimeInstantiator);
        }

        $extensions = static::addExtensions($container, static::DI_EXTENSIONS);

        $loader->load(static::PRIMARY_CONFIGURATION_FILE);

        foreach ($extensions as $ext) {
            $container->loadFromExtension($ext->getAlias());
        }

        static::addCompilerPasses($container, static::DI_COMPILER_PASSES);

        $container->compile($resolveEnvironment);

        return $container;
    }
380315
public function setResolverArguments($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): self
    {
        return $this
            ->setRoot($root)
            ->setArgs($args)
            ->setContext($context)
            ->setResolveInfo($resolveInfo);
    }
392891
public function updateFromEmbeddedApiResponse(array $data, StateInterface $state = null): StateInterface
    {
        if (!$state) {
            $state = $this->stateRepository->findOneByExternalId($data['id']);
            if (!$state) {
                // only update when we create a new because this is the embedded method
                $state = new State();
                $state->setExternalId($data['id'])
                    ->setExclStatistics($data['exclStatistics'])
                    ->setIsDefault($data['isDefault'])
                    ->setName($data['name']);
            }
        }

        return $state;
    }