Mage_Connect_Packager::getDependenciesList PHP Method

getDependenciesList() public method

Get dependencies list/install order info
public getDependenciesList ( string $chanName, string $package, Mage_Connect_Singleconfig $cache, Mage_Connect_Config $config, mixed $versionMax = false, mixed $versionMin = false, $withDepsRecursive = true, $forceRemote = false ) : mixed
$chanName string
$package string
$cache Mage_Connect_Singleconfig
$config Mage_Connect_Config
$versionMax mixed
$versionMin mixed
return mixed
    public function getDependenciesList($chanName, $package, $cache, $config, $versionMax = false, $versionMin = false, $withDepsRecursive = true, $forceRemote = false)
    {
        static $level = 0;
        static $_depsHash = array();
        static $_deps = array();
        static $_failed = array();
        $level++;
        try {
            $chanName = $cache->chanName($chanName);
            $rest = new Mage_Connect_Rest($config->protocol);
            $rest->setChannel($cache->chanUrl($chanName));
            $releases = $rest->getReleases($package);
            if (!$releases || !count($releases)) {
                throw new Exception("No releases for: '{$package}', skipping");
            }
            $state = $config->preffered_state ? $config->preffered_state : 'devel';
            $version = $cache->detectVersionFromRestArray($releases, $versionMin, $versionMax, $state);
            if (!$version) {
                throw new Exception("Version for '{$package}' was not detected");
            }
            $packageInfo = $rest->getPackageReleaseInfo($package, $version);
            if (false === $packageInfo) {
                throw new Exception("Package release '{$package}' not found on server");
            }
            unset($rest);
            $dependencies = $packageInfo->getDependencyPackages();
            $keyOuter = $chanName . "/" . $package;
            //print "Processing outer: {$keyOuter} \n";
            $_depsHash[$keyOuter] = array('name' => $package, 'channel' => $chanName, 'downloaded_version' => $version, 'min' => $versionMin, 'max' => $versionMax, 'packages' => $dependencies);
            if ($withDepsRecursive) {
                $flds = array('name', 'channel', 'min', 'max');
                $fldsCount = count($flds);
                foreach ($dependencies as $row) {
                    foreach ($flds as $key) {
                        $varName = "p" . ucfirst($key);
                        ${$varName} = $row[$key];
                    }
                    $method = __FUNCTION__;
                    $keyInner = $pChannel . "/" . $pName;
                    if (!isset($_depsHash[$keyInner])) {
                        $_deps[] = $row;
                        $this->{$method}($pChannel, $pName, $cache, $config, $pMax, $pMin, $withDepsRecursive, $forceRemote, false);
                    } else {
                        $downloaded = $_depsHash[$keyInner]['downloaded_version'];
                        $hasMin = $_depsHash[$keyInner]['min'];
                        $hasMax = $_depsHash[$keyInner]['max'];
                        if ($pMin === $hasMin && $pMax === $hasMax) {
                            //var_dump("Equal requirements, skipping");
                            continue;
                        }
                        if ($cache->versionInRange($downloaded, $pMin, $pMax)) {
                            //var_dump("Downloaded package matches new range too");
                            continue;
                        }
                        $names = array("pMin", "pMax", "hasMin", "hasMax");
                        for ($i = 0, $c = count($names); $i < $c; $i++) {
                            if (!isset(${$names[$i]})) {
                                continue;
                            }
                            if (false !== ${$names[$i]}) {
                                continue;
                            }
                            ${$names[$i]} = $i % 2 == 0 ? "0" : "999999999";
                        }
                        if (!$cache->hasVersionRangeIntersect($pMin, $pMax, $hasMin, $hasMax)) {
                            $reason = "Detected {$pName} conflict of versions: {$hasMin}-{$hasMax} and {$pMin}-{$pMax}";
                            unset($_depsHash[$keyInner]);
                            $_failed[] = array('name' => $pName, 'channel' => $pChannel, 'max' => $pMax, 'min' => $pMin, 'reason' => $reason);
                            continue;
                        }
                        $newMaxIsLess = version_compare($pMax, $hasMax, "<");
                        $newMinIsGreater = version_compare($pMin, $hasMin, ">");
                        $forceMax = $newMaxIsLess ? $pMax : $hasMax;
                        $forceMin = $newMinIsGreater ? $pMin : $hasMin;
                        //var_dump("Trying to process {$pName} : max {$forceMax} - min {$forceMin}");
                        $this->{$method}($pChannel, $pName, $cache, $config, $forceMax, $forceMin, $withDepsRecursive, $forceRemote);
                    }
                }
            }
        } catch (Exception $e) {
            $_failed[] = array('name' => $package, 'channel' => $chanName, 'max' => $versionMax, 'min' => $versionMin, 'reason' => $e->getMessage());
        }
        $level--;
        if ($level == 0) {
            $out = $this->processDepsHash($_depsHash);
            $deps = $_deps;
            $failed = $_failed;
            $_depsHash = array();
            $_deps = array();
            $_failed = array();
            return array('deps' => $deps, 'result' => $out, 'failed' => $failed);
        }
    }