Adds a new set of packages to the current Composer file.

@param array $packageNames
@param bool  $areDevPackages

@return array List of package's name as a key and the package's version
as value
350637
public function addPackage(array $packageNames, $areDevPackages = false)
    {
        $fs = new Filesystem();
        $file = $this->embeddedComposer->getExternalComposerFilename();

        if ($fs->exists($file) === false) {
            $fs->dumpFile($file, "{\n}\n");
        }

        if (filesize($file) === 0) {
            $fs->dumpFile($file, "{\n}\n");
        }

        $json = new JsonFile($file);

        $requirements = $this->formatPackageNames($packageNames);
        $versionParser = new VersionParser();

        foreach ($requirements as $constraint) {
            $versionParser->parseConstraints($constraint);
        }

        $composerDefinition = $json->read();

        $requireKey = $areDevPackages ? 'require-dev' : 'require';

        foreach ($requirements as $package => $version) {
            $composerDefinition[$requireKey][$package] = $version;
        }

        $json->write($composerDefinition);

        return $composerDefinition[$requireKey];
    }
369178
protected function _packages()
    {
        $installed = static::cache('_composerPackages');
        if (is_array($installed)) {
            return $installed;
        }

        $jsonPath = VENDOR_INCLUDE_PATH . 'composer/installed.json';
        $installed = [];

        if (is_readable($jsonPath)) {
            $json = (array)json_decode(file_get_contents($jsonPath), true);
            foreach ($json as $pkg) {
                $installed[$pkg['name']] = [
                    'name' => $pkg['name'],
                    'version' => $pkg['version'],
                    'version_normalized' => $pkg['version_normalized'],
                ];
            }
        }

        return static::cache('_composerPackages', $installed);
    }
337970
public static function getPackagesAndDependencies($packagesArray)
    {
        foreach ($packagesArray as $key => $value) {
            $packageFile = base_path("/vendor/{$key}/composer.json");

            if ($key !== 'php' && file_exists($packageFile)) {
                $json2 = file_get_contents($packageFile);
                $dependenciesArray = json_decode($json2, true);
                $dependencies = array_key_exists('require', $dependenciesArray) ? $dependenciesArray['require'] : 'No dependencies';
                $devDependencies = array_key_exists('require-dev', $dependenciesArray) ? $dependenciesArray['require-dev'] : 'No dependencies';

                $packages[] = [
                    'name' => $key,
                    'version' => $value,
                    'dependencies' => $dependencies,
                    'dev-dependencies' => $devDependencies
                ];
            }
        }

        return $packages;
    }
543679
public function getPackages()
    {
        if ($this->packages === null) {
            $this->packages = $this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
            $this->packages[] = $this->composer->getPackage();
        }

        return $this->packages;
    }
844390
public Weld addPackages(boolean scanRecursively, Class<?>... packageClasses) {
        for (Class<?> packageClass : packageClasses) {
            addPackage(scanRecursively, packageClass);
        }
        return this;
    }
1003599
protected function getInstalledPackages()
    {
        if ($this->installedPackages === null) {
            $installedPackages = [];
            $packageService = $this->application->make(PackageService::class);
            foreach ($packageService->getInstalledHandles() as $packageHandle) {
                $installedPackages[$packageHandle] = $packageService->getClass($packageHandle);
            }
            $this->installedPackages = $installedPackages;
        }

        return $this->installedPackages;
    }
153437
protected function iterateDependencies(Package $package, $dev = false)
    {
        $deps = $dev ? $package->getDevRequires() : $package->getRequires();
        foreach (array_keys($deps) as $target) {
            if (isset($this->plainList[$target]) && empty($this->orderedList[$target])) {
                $this->iteratePackage($this->plainList[$target]);
            }
        }
    }
173038
public function addClassmap(string $packageName, array $paths): self
    {
        $this->paths['classmap'][$packageName] = $paths;

        return $this;
    }
147569
protected function getCombinesForPackage($packageId)
    {
        $cacheKey = 'packageCombines.'.$packageId;
        $packageCombines = $this->getCachedValue($cacheKey);
        if ($packageCombines === false) {
            $packageCombines = array();

            $data = $this->dataProvider->getData();
            if (isset($data[$packageId])) {
                $info = $data[$packageId];
                if (isset($info['Combines']) && is_array($info['Combines'])) {
                    $packageCombines = $info['Combines'];
                }
            }

            $this->setCachedValue($cacheKey, $packageCombines);
        }

        return $packageCombines;
    }
311240
public function getPackages() : PackageCollection
    {
        if (null === $this->packages) {
            $packages = array_merge(
                array(
                    $this->getName() => $this,
                ),
                $this->getInstalledPackagesFile()->getPackages()->toArray()
            );

            $this->packages = new PackageCollection($packages);
        }

        return $this->packages;
    }
246692
public function loadPackage($names)
    {
        $names = is_array($names) ? $names : func_get_args();

        foreach ($names as $name) {
            if (!array_key_exists($name, $this->packages)) {

                /** @var PackageInterface $package */
                if (!is_null($package = $this->manager->load($name))) {
                    $this->packages[$name] = $package;

                    if ($package->hasDependencies()) {
                        foreach ($package->getDependencies() as $dependency) {
                            $this->loadPackage($dependency);
                        }
                    }
                }
            }
        }

        return $this;
    }
272364
public void addExportedPackages(Set<String> exportedPackages) {
		addExportedPackages(exportedPackages.toArray(new String[exportedPackages.size()]));
	}
1284566
public function sortPackageVersionEntities($packageVersions, $descending = false)
    {
        $keys = [];
        foreach ($packageVersions as $pv) {
            $keys[$pv->getVersion()] = $pv;
        }
        $sortedKeys = $this->sortPackageVersions(array_keys($keys), $descending);
        $result = [];
        foreach ($sortedKeys as $sortedKey) {
            $result[] = $keys[$sortedKey];
        }

        return $result;
    }
680694
private function groupPackagesByName(array $packages): array
    {
        $groupedPackages = [];
        foreach ($packages as $package) {
            $groupedPackages[$package->getName()][] = $package;
        }

        return $groupedPackages;
    }
1272051
protected function convertPacks($packages, $packIds)
    {
        $convertedPacks = new Collection();
        foreach ($packages as $package) {
            if (isset($package->data)) {
                $convertedPacks->add(new PackageContainer($package->data, $packIds));
            }
        }

        return $convertedPacks;
    }
745328
public static function getDecomposerVersion($composerArray, $packages)
    {
        if (isset($composerArray['require'][self::PACKAGE_NAME])) {
            return $composerArray['require'][self::PACKAGE_NAME];
        }

        if (isset($composerArray['require-dev'][self::PACKAGE_NAME])) {
            return $composerArray['require-dev'][self::PACKAGE_NAME];
        }

        foreach ($packages as $package) {
            if (isset($package['dependencies'][self::PACKAGE_NAME])) {
                return $package['dependencies'][self::PACKAGE_NAME];
            }

            if (isset($package['dev-dependencies'][self::PACKAGE_NAME])) {
                return $package['dev-dependencies'][self::PACKAGE_NAME];
            }
        }

        return 'unknown';
    }
808160
private function createPackages(array $packages)
    {
        $matcherPackages = [];

        foreach ($packages as $package) {
            $reflection = new ReflectionClass($package);

            if ($reflection->implementsInterface(self::PACKAGE_REGISTRAR) === false) {
                throw NotAvailableException::createForPackage(self::PACKAGE_REGISTRAR);
            }
            $matcherPackages[] = $reflection->newInstance();
        }

        return $matcherPackages;
    }