Esempio n. 1
0
/**
 * @param array $dependency
 * @param array $installDir	directory where the dependency must be copied to
 * @param array $processed contains list of directories already scanned for dependency
 */
function customInstall($dependency, $installDir, &$processed)
{
    if (isset($dependency['autoload']['psr-0'])) {
        echo "error: The SDK you are trying to install or one of its dependeincies is namespace based. enter the specific version in composer.json to install non-namespace based SDK. Else download the latest SDK from github for namespace based SDK";
        exit;
    }
    $tagUrl = sprintf('https://api.github.com/repos/%s/%s/git/refs/tags/', $dependency['group'], $dependency['artifact']);
    $branchUrl = sprintf('https://api.github.com/repos/%s/%s/git/refs/heads/', $dependency['group'], $dependency['artifact']);
    $branchArray = extractRef($branchUrl);
    $tagsArray = extractRef($tagUrl);
    $dependency['branch'] = getTag($dependency['branch'], $tagsArray, $branchArray);
    // download zip from github
    $downloadUrl = sprintf('https://api.github.com/repos/%s/%s/zipball/%s', $dependency['group'], $dependency['artifact'], $dependency['branch']);
    if (!in_array($downloadUrl, $processed)) {
        echo "Downloading " . $dependency['artifact'] . ' - ' . $dependency['branch'] . PHP_EOL;
        $dest = 'vendor/' . $installDir . '/';
        $fileZip = tempnam(sys_get_temp_dir(), 'ppzip');
        $fp = fopen($fileZip, "w");
        curlExec($downloadUrl, $fp);
        $processed[] = $downloadUrl;
        // extract the downloaded zip
        $zip = new ZipArchive();
        if ($zip->open($fileZip) != "true") {
            echo PHP_EOL . "Could not open {$fileZip}";
            exit;
        }
        $zip->extractTo($dest);
        $zip->close();
        fclose($fp);
        unlink($fileZip);
        // scan extracted directory for nested dependency
        foreach (glob("{$dest}/**/composer.json") as $composer) {
            $json = file_get_contents($composer);
            $json_a = json_decode($json, true);
            $dependencies = getDependency($json_a);
            foreach ($dependencies as $dependency) {
                customInstall($dependency, $dependency['group'], $processed);
            }
        }
    }
}
Esempio n. 2
0
/**
 * @param array $json_a content of composer.json
 * @param array $skipDir contains list of directories already scanned for dependency
 */
function customInstall($downloadUrl, $installDir, $skipDir)
{
    /**
     *  download zip from github
     */
    $fileZip = "tempZip.zip";
    $dest = 'vendor/' . $installDir . '/';
    $tempSourceDir = 'sdk-core-php-composer';
    $fp = fopen("{$fileZip}", "w");
    curlExec($downloadUrl, $fp);
    $zip = new ZipArchive();
    if ($zip->open($fileZip) != "true") {
        echo PHP_EOL . "Could not open {$fileZip}";
        exit;
    }
    /**
     * extract the downloaded zip
     **/
    $zip->extractTo($dest);
    $zip->close();
    fclose($fp);
    unlink($fileZip);
    /**
     * scan extracted directory for nested dependency
     */
    $results = scandir($dest);
    foreach ($results as $result) {
        if ($result === '.' or $result === '..') {
            continue;
        }
        if (is_dir($dest . '/' . $result)) {
            /**
             *  skip the directories already scanned
             */
            if (!in_array($result, $skipDir)) {
                $scannedFiles = scandir($dest . '/' . $result);
                foreach ($scannedFiles as $file) {
                    /**
                     * copy the config file to root directory
                     */
                    if ($file == 'config') {
                        if (!is_dir("config")) {
                            mkdir("config");
                        }
                        copyConfig($dest . '/' . $result . '/' . $file . '/', 'config/');
                        rmdir($dest . '/' . $result . '/' . $file);
                    }
                    if ($file == COMPOSER_FILE) {
                        $json = file_get_contents($dest . '/' . $result . '/' . COMPOSER_FILE);
                        $json_a = json_decode($json, true);
                        $skipDir[] = $result;
                        $dependencies = getDependency($json_a);
                        if (!empty($dependencies)) {
                            foreach ($dependencies as $dependency) {
                                $downloadUrl = 'https://api.github.com/repos/' . $dependency['group'] . '/' . $dependency['artifact'] . '/zipball/' . $dependency['branch'];
                                echo "downloading dependency " . $dependency['artifact'] . '...' . PHP_EOL;
                                customInstall($downloadUrl, $dependency['group'], $skipDir);
                            }
                        }
                    }
                }
            }
        }
    }
}