function main() { $args = $_SERVER['argv']; $script = array_shift($args); $rem_args = array(); $got_args = FALSE; for ($i = 0, $m = count($args); $i < $m; $i++) { $arg = $args[$i]; if (!$got_args && !strncmp($arg, '-', 1)) { usage($script); exit(1); } else { $got_args = TRUE; $rem_args[] = $arg; } } // Retrieve the path to the repository's toplevel directory. $NUL = strncasecmp(PHP_OS, 'Win', 3) ? '/dev/null' : 'NUL'; exec('git rev-parse --show-toplevel 2>' . $NUL, $output, $exitcode); if ($exitcode != 0) { fprintf(STDERR, "Could not determine path to .git folder.%s", PHP_EOL); exit(1); } $dir = trim($output[0]); $composer = get_composer($dir); $type = NULL; foreach ($rem_args as $arg) { if ($type === NULL && !strncmp($arg, '-', 1)) { $type = (string) substr($arg, 1); continue; } else { $type = 'string'; } @settype($arg, $type); $composer = $composer[$arg]; $type = NULL; } echo $composer . PHP_EOL; exit(0); }
function composer($dir) { $composer = get_composer($dir); echo $composer['name'] . PHP_EOL; exit(0); }