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); } } } } } } } } function getDependency($json_a) { $requiredArray = $json_a['require']; foreach ($requiredArray as $key => $val) { if(strpos($key, '/')) { $parts = explode('/', $key); $pos = strpos($val, '-'); if($pos == null || empty($pos)) { $branch = $val; } else { $branch = substr($val, $pos+1); } $batch['group'] = $parts[0] ; $batch['artifact'] = $parts[1]; $batch['branch'] = $branch; $res[] = $batch; } } if(empty($res)) return null; else return $res; } function curlExec($targetUrl, $writeToFile) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$targetUrl); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_FILE, $writeToFile); $res = curl_exec($ch); if (!$res) { echo PHP_EOL . "cURL error number:" .curl_errno($ch); echo PHP_EOL . "cURL error:" . curl_error($ch); exit; } curl_close($ch); } /** * * contributor: https://github.com/rrehbeindoi */ function createAutoload() { $libraryPath = dirname(__FILE__).'/'; $loaderClass = 'PPAutoloader'; $loaderFile = $loaderClass . '.php'; echo "generating autoload file ".PHP_EOL; /** * From comment by "Mike" on http://us2.php.net/manual/en/function.glob.php * * @param string $pattern * @param int $flags - as per glob function * @return array of strings */ function glob_recursive($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); } return $files; } /** * Use built in parser to get class and interface names from a script * * Based on code from http://stackoverflow.com/questions/7153000/get-class-name-from-file * * @param string $source php source to parse * @return array of strings */ function get_classes_defined($source) { $classes = array(); $i = 0; $tokens = token_get_all($source); $length = count($tokens); for ($i = 0; $i < $length; $i++) { if (in_array($tokens[$i][0], array(T_CLASS, T_INTERFACE))) { for ($j = $i + 1; $j < $length; $j++) { if ($tokens[$j] === '{') { $classes[] = $tokens[$i+2][1]; break; } } } } return $classes; } $fileList = glob_recursive($libraryPath . '*.php'); $classes = array(); foreach ($fileList as $file) { // Trim off the absolute path $filename = str_replace($libraryPath, '', $file); if ($filename === $loaderFile) { // Don't include the autoloader in the autoloader map continue; } $found = get_classes_defined(file_get_contents($file)); foreach ($found as $class) { $class = strtolower($class); if (isset($classes[$class])) { ; //echo "Warning: class [{$class}] is defined in both\n\t{$filename}\n\t{$classes[$class]}\n"; } $classes[$class] = $filename; } } ksort($classes, SORT_STRING); $classList = var_export($classes, true); $script = <<< SCRIPT