Collects the manifest data for all packages in the given package states array

@param array $packageStates
@return array
481260
protected function collectPackageManifestData(array $packageStates)
    {
        return array_map(function ($packageState) {
            return ComposerUtility::getComposerManifest(Files::getNormalizedPath(Files::concatenatePaths([$this->packagesBasePath, $packageState['packagePath']])));
        }, $packageStates['packages']);
    }
710615
protected function _getPackages( $manifest, $filter = array() )
	{
		$packageContainer = array();

		if( !isset( $manifest->pkgs ) || !is_array( $manifest->pkgs ) ) {
			throw new MW_Jsb2_Exception( 'No packages found' );
		}

		foreach( $manifest->pkgs as $package )
		{
			if( !isset( $package->name ) || !isset( $package->file ) || !is_object( $package ) ) {
				throw new MW_Jsb2_Exception( 'Invalid package content' );
			}

			if( !isset( $package->fileIncludes ) || !is_array( $package->fileIncludes ) ) {
				throw new MW_Jsb2_Exception( 'No files in package found' );
			}

			if( !in_array( $package->name, $filter ) ) {
				$packageContainer[ pathinfo( $package->file, PATHINFO_EXTENSION ) ][] = $package;
			}
		}

		return $packageContainer;
	}
52760
public function getPackagesTranslations($onlyInstalled = false)
    {
        $result = [];
        $ps = $this->app->make(PackageService::class);
        foreach ($ps->getAvailablePackages($onlyInstalled) as $package) {
            $result[] = $this->getPackageTranslations($package);
        }

        return $result;
    }
367026
public function getPackages()
    {
        if (null === $this->packages) {
            $this->packages = $this->findPackages();
        }

        return $this->packages;
    }
253973
private function getSupportedPackages(array $packages)
    {
        $supported_packages = [];
        foreach ($packages as $package) {
            /* @var $package \Composer\Package\PackageInterface */
            if ($this->supportsPackage($package)) {
                $supported_packages[] = $package;
            }
        }
        return $supported_packages;
    }
72939
protected function _getManifests( array $directories )
	{
		$manifests = array();

		foreach ( $directories as $directory )
		{
			if ( ( $manifest = $this->_getManifestFile( $directory ) ) !== false )
			{
				$manifests[ $directory ] = $manifest;
				continue;
			}

			$dir = new DirectoryIterator( $directory );

			foreach ( $dir as $dirinfo )
			{
				if ( $dirinfo->isDot() === false )
				{
					if ( ( $manifest = $this->_getManifestFile( $dirinfo->getPathName() ) ) !== false ) {
						$manifests[$dirinfo->getPathName()] = $manifest;
					}
				}
			}
		}

		return $manifests;
	}
561917
private function removeDuplicates(array $packages): array
    {
        /** @var bool[] $registeredPackages */
        $registeredPackages = [];

        $result = array_filter(
            $packages,
            function (PackageInterface $package) use (&$registeredPackages) {
                $packageName = $package->getName();
                if (isset($registeredPackages[$packageName])) {
                    return false;
                }

                $registeredPackages[$packageName] = true;
                return true;
            }
        );

        return $result;
    }
1198720
public function getAvailablePackages($onlyNotInstalled = true)
    {
        $dh = $this->application->make('helper/file');
        $packages = $dh->getDirectoryContents(DIR_PACKAGES);
        if ($onlyNotInstalled) {
            $handles = $this->getInstalledHandles();
            $packages = array_diff($packages, $handles);
        }

        if (count($packages) > 0) {
            $packagesTemp = [];
            // get package objects from the file system
            foreach ($packages as $p) {
                if (file_exists(DIR_PACKAGES . '/' . $p . '/' . FILENAME_CONTROLLER)) {
                    $pkg = $this->getClass($p);
                    if (!empty($pkg)) {
                        $packagesTemp[] = $pkg;
                    }
                }
            }
            $packages = $packagesTemp;
        }

        return $packages;
    }
1221117
private function get_packages()
    {
        if ($this->input->getOption('all') === true) {
            $packages = [];
            
            // Add all package files to $packages array.
            foreach (Config::get('services.providers') as $package) {
                $packages[ $package ] = $package::get_files_to_publish();
            }

            return $packages;
        }

        $package = $this->input->getOption('package');

        // If no package specified.
        if ($package === null) {
            $package = $this->package_prompt();
        }

        // If the package chosen does not exist.
        if (! \class_exists($package)) {
            $this->output->writeln("<error>The package [$package] could not be found.</error>");
            exit;
        }

        // When running publish via the theme installer, the current theme isn't active yet.
        // We need to trick WP into thinking it is.
        if (isset($this->root)) {
            $parts = \explode('/', $this->root);

            if ($parts[0] == $this->root) {
                $parts = \explode('\\', $this->root);
            }

            $theme_name = \end($parts);

            \add_filter(
                'stylesheet',
                function () use ($theme_name) {
                    return $theme_name;
                }
            );
            \add_filter(
                'template',
                function () use ($theme_name) {
                    return $theme_name;
                }
            );

            // Resolve the package manually.
            $provider = Container::resolve($package);
            $provider->register();
        }

        return [
            $package => $package::get_files_to_publish(),
        ];
    }
234771
protected function listPackageClasses(array $namespaces)
    {
        return array_filter(get_declared_classes(), function ($class) use ($namespaces) {
            $valid = false;
            foreach ($namespaces as $ns) {
                $valid = (strpos($class, $ns) === 0) ? true : $valid;
            }
            return $valid;
        });
    }
1083722
public function getPackageInfo($packageList)
    {
        $formatInfo = function ($package) {
            // Convert object to array, with Capitalised keys
            $package = get_object_vars($package);
            return array_combine(
                array_map('ucfirst', array_keys($package)),
                $package
            );
        };

        $packageList = array_map($formatInfo, $packageList);
        $this->extend('updatePackageInfo', $packageList);
        return $packageList;
    }
276041
protected function generateRequirePackages(array $packagePairs)
    {
        $requires = [];

        foreach ($packagePairs as $packagePair) {
            $requires[$packagePair->getName()] = $packagePair->getVersion();
        }

        return $requires;
    }
512233
protected function scanAvailablePackages()
    {
        $newPackageStatesConfiguration = ['packages' => []];
        foreach ($this->findComposerPackagesInPath($this->packagesBasePath) as $packagePath) {
            $composerManifest = ComposerUtility::getComposerManifest($packagePath);
            if (!isset($composerManifest['name'])) {
                throw new InvalidConfigurationException(sprintf('A package composer.json was found at "%s" that contained no "name".', $packagePath), 1445933572);
            }

            if (strpos($packagePath, Files::concatenatePaths([$this->packagesBasePath, 'Inactive'])) === 0) {
                // Skip packages in legacy "Inactive" folder.
                continue;
            }

            $packageKey = $this->getPackageKeyFromManifest($composerManifest, $packagePath);
            $this->composerNameToPackageKeyMap[strtolower($composerManifest['name'])] = $packageKey;

            $packageConfiguration = $this->preparePackageStateConfiguration($packageKey, $packagePath, $composerManifest);
            if (isset($newPackageStatesConfiguration['packages'][$composerManifest['name']])) {
                throw new PackageException(
                    sprintf('The package with the name "%s" was found more than once, please make sure it exists only once. Paths "%s" and "%s".',
                        $composerManifest['name'],
                        $packageConfiguration['packagePath'],
                        $newPackageStatesConfiguration['packages'][$composerManifest['name']]['packagePath']),
                    1493030262
                );
            }

            $newPackageStatesConfiguration['packages'][$composerManifest['name']] = $packageConfiguration;
        }

        return $newPackageStatesConfiguration;
    }
1094883
protected function getPackages()
	{
		if ( ! is_null($package = $this->input->getArgument('package')))
		{
			return array($package);
		}
		elseif ( ! is_null($bench = $this->input->getOption('bench')))
		{
			return array($bench);
		}

		return $this->findAllAssetPackages();
	}
875678
public function getAllInstalledPackages(bool $rescan = false): array
    {
        if (!$rescan && !empty(self::$allInstalledPackages)) {
            return self::$allInstalledPackages;
        }

        $compiledFile = $this->pathHelper->realize('{MELIOR_BASE}/Data/Persistent/Compiler/Packages/package.map');
        if (!$rescan && is_file($compiledFile)) {
            $result = \unserialize(\file_get_contents($compiledFile));
        } else {
            $result = array_merge(
                $this->getLibraries($rescan),
                $this->getPlugins($rescan),
                $this->getApplicationPackages($rescan)
            );
        }

        self::$allInstalledPackages = $result;

        return $result;
    }
321459
protected function registerPackagesFromConfiguration($packageStatesConfiguration)
    {
        foreach ($packageStatesConfiguration['packages'] as $composerName => $packageStateConfiguration) {
            $this->registerPackageFromStateConfiguration($composerName, $packageStateConfiguration);
        }
    }
580077
public function findAll(): array
    {
        $rootPackage = $this->composer->getPackage();
        $dependencies = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();

        $packagesWithDuplicates = array_merge([$rootPackage], $dependencies);

        return $this->removeDuplicates($packagesWithDuplicates);
    }