Tries to sort packages from the given list before the named package key.
Ignores non existing packages and any composer key without "/" (eg. "php").

@param string $packageKey
@param string[] $packagesToLoadBefore
@return int
161257
protected function sortListBefore($packageKey, array $packagesToLoadBefore)
    {
        $unresolvedDependencies = 0;
        foreach ($packagesToLoadBefore as $composerNameToLoadBefore) {
            if (!$this->packageRequirementIsComposerPackage($composerNameToLoadBefore)) {
                continue;
            }

            if (isset($this->sortedPackages[$packageKey])) {
                // "Success" case: a required package is already sorted in front of our current $packageKey.
                continue;
            }

            if (isset($this->unsortedPackages[$composerNameToLoadBefore])) {
                $resolved = $this->sortPackage($composerNameToLoadBefore);
                if (!$resolved) {
                    $unresolvedDependencies++;
                }
            }
        }

        return $unresolvedDependencies;
    }
1051288
public function checkPackagesCanBeInstalled($packages_names_list)
    {
        foreach ($packages_names_list as $package_name) {
            $this->checkNoOtherPackageNeedsThisDependencyInALowerVersion($package_name,
                $this->getLatestVersionOfPackage($package_name), $packages_names_list);
        }
    }
87529
public function unfreezePackage($packageKey)
    {
        if (!$this->isPackageFrozen($packageKey)) {
            return;
        }
        if (!isset($this->packages[$packageKey])) {
            return;
        }
        $composerName = $this->packages[$packageKey]->getComposerName();

        $this->bootstrap->getObjectManager()->get(ReflectionService::class)->unfreezePackageReflection($packageKey);

        unset($this->packageStatesConfiguration['packages'][$composerName]['frozen']);
        $this->savePackageStates($this->packageStatesConfiguration);
    }
1271423
public function getForPackage($package, $key, $default = null)
    {
        if (empty($this->packagesConfiguration[$package])) {
            return $default;
        }
        return Arr::get($this->packagesConfiguration[$package], $key, $default);
    }
901921
protected function filterArrayByClassesInPackageNamespace(array $array, $packageKey)
    {
        return array_filter($array, function ($className) use ($packageKey) {
            return (isset($this->availableClassNames[$packageKey]) && in_array($className, $this->availableClassNames[$packageKey]));
        }, ARRAY_FILTER_USE_KEY);
    }
1161234
public function importFromPackage($packageKey)
    {
        if (!$this->packageManager->isPackageAvailable($packageKey)) {
            throw new NeosException(sprintf('Error: Package "%s" is not active.', $packageKey), 1384192950);
        }
        $contentPathAndFilename = sprintf('resource://%s/Private/Content/Sites.xml', $packageKey);
        if (!file_exists($contentPathAndFilename)) {
            throw new NeosException(sprintf('Error: No content found in package "%s".', $packageKey), 1384192955);
        }
        try {
            return $this->importFromFile($contentPathAndFilename);
        } catch (\Exception $exception) {
            throw new NeosException(sprintf('Error: During import an exception occurred: "%s".', $exception->getMessage()), 1300360480, $exception);
        }
    }
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;
    }
582509
public function isPackageFrozen($packageKey)
    {
        if (!isset($this->packages[$packageKey])) {
            return false;
        }
        $composerName = $this->packages[$packageKey]->getComposerName();

        return (
            $this->bootstrap->getContext()->isDevelopment()
            && isset($this->packageStatesConfiguration['packages'][$composerName]['frozen'])
            && $this->packageStatesConfiguration['packages'][$composerName]['frozen'] === true
        );
    }
687833
public static function get_by_package($package_name = 'project') {
		if (!file_exists(Config::$migration_directory)) {
			throw new \Exception('Config::$migration_directory is not set to a valid directory');
		}

		/**
		 * Array with results
		 */
		$migrations = [];

		if ($package_name == 'project') {
			$files = scandir(Config::$migration_directory, SCANDIR_SORT_ASCENDING);

			foreach ($files as $key => $file) {
				if ($file[0] == '.') {
					unset($files[$key]);
					continue;
				}

				if ($file == 'db_version') {
					unset($files[$key]);
					continue;
				}

				if (!preg_match("/^\d{8}_\d{6}_.*$/", $file)) {
					unset($files[$key]);
					continue;
				}


				$parts = explode('_', $file);
				foreach ($parts as $key => $part) {
					$parts[$key] = ucfirst($part);
				}

				$classname = 'Migration_' . str_replace('.php', '', implode('_', $parts));
				include_once Config::$migration_directory . '/' . $file;
				$migrations[] = new $classname();
			}
		} else {

			/**
			 * Make a list of all migrations to be execute
			 */
			$packages = \Skeleton\Core\Skeleton::get_all();

			foreach ($packages as $package) {
				if ($package->name != $package_name) {
					continue;
				}
				if (!file_exists($package->migration_path)) {
					continue;
				}
				$files = scandir($package->migration_path, SCANDIR_SORT_ASCENDING);

				foreach ($files as $key => $file) {
					if ($file[0] == '.') {
						unset($files[$key]);
						continue;
					}

					if ($file == 'db_version') {
						unset($files[$key]);
						continue;
					}

					if (!preg_match("/^\d{8}_\d{6}_.*$/", $file)) {
						unset($files[$key]);
						continue;
					}


					$parts = explode('_', $file);
					foreach ($parts as $key => $part) {
						$parts[$key] = ucfirst($part);
					}

					$namespace_parts = explode('-', $package->name);
					foreach ($namespace_parts as $key => $namespace_part) {
						$namespace_parts[$key] = ucfirst($namespace_part);
					}
					$namespace = implode('\\', $namespace_parts);

					$classname = $namespace . '\Migration_' . str_replace('.php', '', implode('_', $parts));
					include_once $package->migration_path . '/' . $file;
					$migrations[] = new $classname();
				}
			}
		}


		return $migrations;
	}
865177
protected function getDependsForPackage($packageId)
    {
        $cacheKey = 'packageDepends.'.$packageId;
        $packageDepends = $this->getCachedValue($cacheKey);
        if ($packageDepends === false) {
            $packageDepends = array();

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

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

        return $packageDepends;
    }
242646
public static function postPackageUpdateAndInstall(PackageEvent $event)
    {
        $operation = $event->getOperation();
        if (!$operation instanceof InstallOperation && !$operation instanceof UpdateOperation) {
            throw new Exception\UnexpectedOperationException('Handling of operation with type "' . $operation->getJobType() . '" not supported', 1348750840);
        }
        $package = ($operation->getJobType() === 'install') ? $operation->getPackage() : $operation->getTargetPackage();
        $packageExtraConfig = $package->getExtra();
        $installPath = $event->getComposer()->getInstallationManager()->getInstallPath($package);

        $evaluatedInstallerResources = false;
        if (isset($packageExtraConfig['neos']['installer-resource-folders'])) {
            foreach ($packageExtraConfig['neos']['installer-resource-folders'] as $installerResourceDirectory) {
                static::copyDistributionFiles($installPath . $installerResourceDirectory);
            }
            $evaluatedInstallerResources = true;
        }

        if ($operation->getJobType() === 'install') {
            if (isset($packageExtraConfig['typo3/flow']['post-install'])) {
                self::runPackageScripts($packageExtraConfig['typo3/flow']['post-install']);
            }
            if (isset($packageExtraConfig['neos/flow']['post-install'])) {
                self::runPackageScripts($packageExtraConfig['neos/flow']['post-install']);
            }
        }

        if ($operation->getJobType() === 'update') {
            if (isset($packageExtraConfig['typo3/flow']['post-update'])) {
                self::runPackageScripts($packageExtraConfig['typo3/flow']['post-update']);
            }
            if (isset($packageExtraConfig['neos/flow']['post-update'])) {
                self::runPackageScripts($packageExtraConfig['neos/flow']['post-update']);
            }
        }

        // TODO: Deprecated from Flow 3.1 remove three versions after.
        if (!$evaluatedInstallerResources && isset($packageExtraConfig['typo3/flow']['manage-resources']) && $packageExtraConfig['typo3/flow']['manage-resources'] === true) {
            static::copyDistributionFiles($installPath . 'Resources/Private/Installer/');
        }
    }
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;
    }
1059315
public function get($key, $default = null, $package = null)
    {
        if ($package) {
            return $this->getForPackage($package, $key, $default);
        }
        return Arr::get($this->mainConfiguration, $key, $default);

    }
47192
protected function packageExists($packageKey, Node $node, CMS $application, Deployment $deployment, array $options = [])
    {
        $webDirectory = isset($options['webDirectory']) ? trim($options['webDirectory'], '\\/') : '';
        return $this->directoryExists($webDirectory . '/typo3conf/ext/' . $packageKey, $node, $application, $deployment, $options);
    }
68357
public static function prePackageUninstall(PackageEvent $event){
		$installedPackage = $event->getOperation()->getPackage()->getName();
		if (self::checkConfig($event, $installedPackage)) {
			self::phinxRollbackFromPackageName($event, $installedPackage);
		} else {
			die();
		}
	}
106385
public static function copyPackage($package_file, $tmp)
    {
        $package_file = realpath($package_file);

        if (file_exists($package_file)) {
            $filename = basename($package_file);
            Folder::create($tmp);
            copy(realpath($package_file), $tmp . DS . $filename);
            return $tmp . DS . $filename;
        }

        return null;
    }
777633
private static function _updatePackage($packageName)
	{
		self::_init();
		self::_dispatch('update');
		if (is_null($packageName))
		{
			$package = array();
		}
		elseif (is_string($packageName))
		{
			$package = array($packageName);
		}
		else
		{
			$package = $packageName;
		}
		$installer = self::_getInstaller();
		$installer
			->setUpdate(true)
			->setUpdateWhitelist($package);
		return $installer->run();
	}