Convert the data of a complete package to the passed json array.

@param CompletePackageInterface $package The package to process.

@param JsonArray                $data    The json array to push the data to.

@return void
967965
private function convertCompletePackage(CompletePackageInterface $package, $data)
    {
        $data->set('description', $package->getDescription());
        $data->set('license', $package->getLicense());
        if ($keywords = $package->getKeywords()) {
            $data->set('keywords', $keywords);
        }
        if ($homepage = $package->getHomepage()) {
            $data->set('homepage', $homepage);
        }
        if ($authors = $package->getAuthors()) {
            $data->set('authors', $authors);
        }
        if ($support = $package->getSupport()) {
            $data->set('support', $support);
        }
        if ($extra = $package->getExtra()) {
            $data->set('extra', $extra);
        }
        $data->set('abandoned', $package->isAbandoned());
        if ($package->isAbandoned()) {
            $data->set('replacement', $package->getReplacementPackage());
        }
    }
1210868
public function importJson($jsonData)
    {
        $json = json_decode($jsonData, true);

        if ($json === null) {
            throw new \InvalidArgumentException("Footprint json is not a valid");
        }

        if (!is_array($json)) {
            throw new \InvalidArgumentException("Footprint json data is not a valid");
        }

        $this->_data += $json;
    }
1079680
public function execute(array $package)
    {
        $this->getComposer();
        $io = $this->getIO();

        /** @var \Bolt\Filesystem\Handler\JsonFile $jsonFile */
        $jsonFile = $this->getOptions()->composerJson();
        $newlyCreated = !$jsonFile->exists();

        if ($newlyCreated) {
            $this->app['extend.manager.json']->update();
        }

        // Format the package array
        $package = $this->formatRequirements($package);

        // Validate requirements format
        $versionParser = new VersionParser();
        foreach ($package as $constraint) {
            $versionParser->parseConstraints($constraint);
        }

        // Get a back up of the file contents
        $composerBackup = $jsonFile->parse();

        // Update our JSON file now with a specific version.
        // This is what Composer will read, and use, internally during the process.
        // After that is complete, we'll re-save with a constraint
        $this->updateComposerJson($jsonFile, $package, false);

        // JSON file has been created/updated, if we're not installing, exit
        if ($this->getOptions()->noUpdate()) {
            return 0;
        }

        // Reload Composer config
        $composer = $this->resetComposer();

        /** @var $install \Composer\Installer */
        $install = Installer::create($io, $composer)
            ->setVerbose($this->getOptions()->verbose())
            ->setPreferSource($this->getOptions()->preferSource())
            ->setPreferDist($this->getOptions()->preferDist())
            ->setDevMode(!$this->getOptions()->updateNoDev())
            ->setOptimizeAutoloader($this->getOptions()->optimizeAutoloader())
            ->setClassMapAuthoritative($this->getOptions()->classmapAuthoritative())
            ->setUpdate($this->getOptions()->update())
            ->setUpdateWhitelist(array_keys($package))
            ->setWhitelistDependencies($this->getOptions()->updateWithDependencies())
            ->setIgnorePlatformRequirements($this->getOptions()->ignorePlatformReqs())
            ->setRunScripts(!$this->getOptions()->noScripts())
        ;

        try {
            $status = $install->run();
            if ($status !== 0) {
                if ($newlyCreated) {
                    // Installation failed, deleting JSON
                    $jsonFile->delete();
                } else {
                    // Installation failed, reverting JSON to its original content
                    $jsonFile->dump($composerBackup);
                }
            }
            // Update our JSON file now with a constraint
            $this->updateComposerJson($jsonFile, $package, true);

            return $status;
        } catch (\Exception $e) {
            // Installation failed, reverting JSON to its original content
            $jsonFile->dump($composerBackup);

            $msg = sprintf('%s received an error from Composer: %s in %s::%s', __METHOD__, $e->getMessage(), $e->getFile(), $e->getLine());
            $this->app['logger.system']->critical($msg, ['event' => 'exception', 'exception' => $e]);
            throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
        }
    }
843369
public function importDataV1x(array $data)
    {
        $this->_packageXml = null;
        $this->_init();
        // Import simple data
        if (isset($data['name'])) {
            $this->setName($data['name']);
        }
        if (isset($data['summary'])) {
            $this->setSummary($data['summary']);
        }
        if (isset($data['description'])) {
            $this->setDescription($data['description']);
        }
        if (isset($data['channel'])) {
            $this->setChannel($this->convertChannelFromV1x($data['channel']));
        }
        if (isset($data['license'])) {
            if (is_array($data['license'])) {
                $this->setLicense($data['license']['_content'], $data['license']['attribs']['uri']);
            } else {
                $this->setLicense($data['license']);
            }
        }
        if (isset($data['version'])) {
            $this->setVersion($data['version']['release']);
        }
        if (isset($data['stability'])) {
            $this->setStability($data['stability']['release']);
        }
        if (isset($data['notes'])) {
            $this->setNotes($data['notes']);
        }
        if (isset($data['date'])) {
            $this->setDate($data['date']);
        }
        if (isset($data['time'])) {
            $this->setTime($data['time']);
        }

        // Import authors
        $authors = array();
        $authorRoles = array('lead', 'developer', 'contributor', 'helper');
        foreach ($authorRoles as $authorRole) {
            if (isset($data[$authorRole])) {
                $authorList = $data[$authorRole];
                if (!is_array($authorList) || isset($authorList['name'])) {
                    $authorList = array($authorList);
                }
                foreach ($authorList as $authorRawData) {
                    $author = array();
                    $author['name'] = $authorRawData['name'];
                    $author['user'] = $authorRawData['user'];
                    $author['email'] = $authorRawData['email'];
                    array_push($authors, $author);
                }
            }
        }
        $this->setAuthors($authors);

        // Import dependencies
        $packages = array();
        $extensions = array();
        if (isset($data['dependencies']) && is_array($data['dependencies'])) {
            $dependencySections = array('required', 'optional');
            $elementTypes = array('package', 'extension');
            foreach ($dependencySections as $dependencySection) {
                if (isset($data['dependencies'][$dependencySection])) {
                    // Handle required PHP version
                    if ($dependencySection == 'required' && isset($data['dependencies']['required']['php'])) {
                        $this->setDependencyPhpVersion($data['dependencies']['required']['php']['min'], $data['dependencies']['required']['php']['max']);
                    }
                    // Handle extensions
                    if (isset($data['dependencies'][$dependencySection]['extension'])) {
                        $extensionList = $data['dependencies'][$dependencySection]['extension'];
                        if (!is_array($extensionList) || isset($extensionList['name'])) {
                            $extensionList = array($extensionList);
                        }
                        foreach ($extensionList as $extensionRawData) {
                            $extension = array();
                            $extension['name'] = $extensionRawData['name'];
                            $extension['min_version'] = isset($extensionRawData['min']) ? $extensionRawData['min'] : null;
                            $extension['max_version'] = isset($extensionRawData['max']) ? $extensionRawData['max'] : null;
                            array_push($extensions, $extension);
                        }
                    }
                    // Handle packages
                    if (isset($data['dependencies'][$dependencySection]['package'])) {
                        $packageList = $data['dependencies'][$dependencySection]['package'];
                        if (!is_array($packageList) || isset($packageList['name'])) {
                            $packageList = array($packageList);
                        }
                        foreach ($packageList as $packageRawData) {
                            $package = array();
                            $package['name'] = $packageRawData['name'];
                            $package['channel'] = $this->convertChannelFromV1x($packageRawData['channel']);
                            $package['min_version'] = isset($packageRawData['min']) ? $packageRawData['min'] : null;
                            $package['max_version'] = isset($packageRawData['max']) ? $packageRawData['max'] : null;
                            array_push($packages, $package);
                        }
                    }
                }
            }
        }
        $this->setDependencyPackages($packages);
        $this->setDependencyPhpExtensions($extensions);

        // Import contents
        if (isset($data['contents']) && is_array($data['contents']) && is_array($data['contents']['dir'])) {
            // Handle files
            $root = $data['contents']['dir'];
            if (isset($data['contents']['dir']['file'])) {
                $fileList = $data['contents']['dir']['file'];
                if (!is_array($fileList) || isset($fileList['attribs'])) {
                    $fileList = array($fileList);
                }
                foreach ($fileList as $fileRawData) {
                    $targetName = $fileRawData['attribs']['role'];
                    $parentTargetNode = $this->_getNode('target', $this->_packageXml->contents, $targetName);
                    $filePath = $fileRawData['attribs']['name'];
                    $filePathParts = explode('/', $filePath);
                    $fileName = array_pop($filePathParts);
                    $parentDirNode = null;
                    if (!empty($filePathParts)) {
                        $parentDirNode = $parentTargetNode;
                        foreach ($filePathParts as $directoryName) {
                            $parentDirNode = $this->_getNode('dir', $parentDirNode, $directoryName);
                        }
                    } else {
                        $parentDirNode = $this->_getNode('dir', $parentTargetNode, '.');
                    }
                    $fileNode = $parentDirNode->addChild('file');
                    $fileNode->addAttribute('name', $fileName);
                    $fileNode->addAttribute('hash', $fileRawData['attribs']['md5sum']);
                }
            }
        }

        return $this;
    }
364833
public function movePackage($package)
    {
        if (! empty($package->dependencies)) {
            foreach ($package->dependencies as $dependency) {
                $this->movePackage($dependency);
            }
        }

        $this->mover->movePackage($package);
    }
1278591
protected function processPackage(Package $package)
    {
        $extra = $package->getExtra();
        $files = isset($extra[self::EXTRA_OPTION_NAME]) ? $extra[self::EXTRA_OPTION_NAME] : null;
        $this->originalFiles[$package->getPrettyName()] = $files;

        if (is_array($files)) {
            $this->addFiles($package, $files);
        }
        if ($package->isRoot()) {
            $this->loadDotEnv($package);
            if (!empty($extra[self::EXTRA_DEV_OPTION_NAME])) {
                $this->addFiles($package, $extra[self::EXTRA_DEV_OPTION_NAME]);
            }
        }

        $aliases = $package->collectAliases();

        $this->builder->mergeAliases($aliases);
        $this->builder->setPackage($package->getPrettyName(), array_filter([
            'name' => $package->getPrettyName(),
            'version' => $package->getVersion(),
            'reference' => $package->getSourceReference() ?: $package->getDistReference(),
            'aliases' => $aliases,
        ]));
    }
876509
public static function saveJSON($data, $filename, $jsonFlag = 0)
    {
        $content = json_encode($data, $jsonFlag);
        self::save($filename, $content);
    }
279053
private function addScriptsTo(CompletePackage $package)
    {
        $scripts = $package->getScripts();
        $scripts = array_merge_recursive($scripts, $this->getScripts());

        $package->setScripts($scripts);
    }
1310312
protected function finish(ContainerInterface $container)
	{
		foreach ($this->getPackages() as $package) {
			$package->finish($container);
		}
	}
1058886
public function unlockPackage(PackageInterface $package)
    {
        $name = $package->getPrettyName();
        $lock = 'extra/tenside/version-locks/' . $this->escape($name);

        // Nothing to do?
        if (!$this->has($lock)) {
            return $this;
        }

        if (false === ($constraint = $this->get($lock))) {
            $this->remove($lock);
            $this->requirePackage($name, null);
            $this->cleanEmptyArraysInPath('extra/tenside');

            return $this;
        }

        $this->requirePackage($name, $constraint);
        $this->remove($lock);
        $this->cleanEmptyArraysInPath('extra/tenside');

        return $this;
    }
155485
public function resetPackage(WritableRepositoryInterface $repository, PackageInterface $package)
    {
        $verbosityLevel = OutputUtils::resetVerbosity($this->appIO, OutputInterface::VERBOSITY_QUIET);

        $operation = new ResetOperation($package, 'Package reset due to changes in patches configuration');

        if (!$this->packageResetStrategy->shouldAllowReset($package)) {
            OutputUtils::resetVerbosity($this->appIO, $verbosityLevel);

            throw new \Vaimo\ComposerPatches\Exceptions\PackageResetException(
                sprintf('Package reset halted due to encountering local changes: %s', $package->getName())
            );
        }

        try {
            $this->installer->install($repository, $operation);
        } catch (\Exception $exception) {
            OutputUtils::resetVerbosity($this->appIO, $verbosityLevel);

            throw $exception;
        }

        OutputUtils::resetVerbosity($this->appIO, $verbosityLevel);
    }
78067
public function package(string $package, ?string $namespace = null) : void {
        if (is_null($namespace)) {
            list($vendor, $namespace) = explode('/', $package);
        }

        $this->finder->addNamespace($namespace, $package);
    }
654136
public function parseComposerExtra(PackageInterface $package, $assets_package_dir, $vendor_package_dir)
    {
        $data = $this->_autoloader->getAssetsInstaller()->parseComposerExtra($package, $assets_package_dir);
        if (is_null($data)) {
            $data = array();
        }
        $extra = $package->getExtra();
        $assets_package_dir = rtrim($assets_package_dir, '/') . '/';
        if (strlen($vendor_package_dir)) {
            $vendor_package_dir = rtrim($vendor_package_dir, '/') . '/';
        }

        $mapping = array(
            'layouts'=>'layouts_path',
            'views'=>'views_path',
            'views-functions'=>'views_functions'
        );
        foreach ($mapping as $json_name=>$var_name) {
            if (isset($extra[$json_name])) {
                $json_vals = is_array($extra[$json_name]) ? $extra[$json_name] : array($extra[$json_name]);
                $data[$var_name] = array();
                foreach ($json_vals as $json_val) {
                    $data[$var_name][] = $vendor_package_dir . $json_val;
                }
            }
        }
/*
        if (isset($extra['layouts'])) {
            $layouts = is_array($extra['layouts']) ? $extra['layouts'] : array($extra['layouts']);
            $data['layouts_path'] = array();
            foreach ($layouts as $layout_path) {
                $data['layouts_path'][] = $vendor_package_dir . $layout_path;
            }
        }

        if (isset($extra['views'])) {
            $views = is_array($extra['views']) ? $extra['views'] : array($extra['views']);
            $data['views_path'] = array();
            foreach ($views as $view_path) {
                $data['views_path'][] = $vendor_package_dir . $view_path;
            }
        }

        if (isset($extra['views-functions'])) {
            $views_fcts = is_array($extra['views-functions']) ? $extra['views-functions'] : array($extra['views-functions']);
            $data['views_functions'] = array();
            foreach ($views_fcts as $view_fct_path) {
                $data['views_functions'][] = $vendor_package_dir . $view_fct_path;
            }
        }
*/
        return !empty($data) ? $data : null;
    }
1133967
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) {
        parent::install($repo, $package);
        $instructions = $this->getInstructions($package);
        if (!$instructions || empty($instructions['install'])) { return; }
        $this->handleInstructions($package, $instructions['install']);
    }
421726
protected function removeAssets(PackageInterface $package)
    {
        $assets = $this->getPackageAssetsDir($package);
        if (!$assets) {
            return;
        }

        $target = $this->getAssetsInstallPath($package);
        if (file_exists($target)) {
            $this->io->write(
                sprintf('  - Removing <info>%s</info> assets from <info>%s</info>',
                    $package->getPrettyName(),
                    str_replace(dirname($this->assets_dir) . '/', '', $target)
                )
            );
            $this->filesystem->remove($target);
            Dispatch::unregisterPackage($package, $this);
            $this->io->write('');
        } else {
            Error::thrower(
                sprintf('Unable to find assets from package "%s"', $package->getPrettyName()),
                '\InvalidArgumentException', __CLASS__, __METHOD__, __LINE__
            );
        }
    }
1360022
protected function loadRealPackage(LazyPackageInterface $package)
    {
        $realPackage = false;

        try {
            $data = $this->driver->getComposerInformation($this->identifier);
            $valid = \is_array($data);
            $data = $this->preProcess($this->driver, $this->validateData($data), $this->identifier);

            if ($this->verbose) {
                $this->io->write('Importing '.($valid ? '' : 'empty ').$this->type.' '.$data['version'].' ('.$data['version_normalized'].')');
            }

            /** @var CompletePackageInterface $realPackage */
            $realPackage = $this->loader->load($data);
        } catch (\Exception $e) {
            if ($this->verbose) {
                $filename = $this->assetType->getFilename();
                $this->io->write('<'.$this->getIoTag().'>Skipped '.$this->type.' '.$package->getPrettyVersion().', '.($e instanceof TransportException ? 'no '.$filename.' file was found' : $e->getMessage()).'</'.$this->getIoTag().'>');
            }
        }
        $this->driver->cleanup();

        return $realPackage;
    }
608745
public static function registerPackage(PackageInterface $package, $target, AssetsInstallerInterface $installer = null)
    {
        self::$__autoloader->registerPackage($package, $target, $installer);
    }