public function separateProjectsFromArgs($argv, $options)
{
$cgrCommands = array('require', 'update', 'remove');
$command = 'require';
$composerArgs = array();
$projects = array();
$globalMode = !$options['composer'];
foreach ($argv as $arg) {
if ($arg[0] == '-') {
// Any flags (first character is '-') will just be passed
// through to to composer. Flags interpreted by cgr have
// already been removed from $argv.
$composerArgs[] = $arg;
} elseif (strpos($arg, '/') !== false) {
// Arguments containing a '/' name projects. We will split
// the project from its version, allowing the separator
// character to be either a '=' or a ':', and then store the
// result in the $projects array.
$projectAndVersion = explode(':', strtr($arg, '=', ':'), 2) + array('', '');
list($project, $version) = $projectAndVersion;
$projects[$project] = $version;
} elseif ($this->isComposerVersion($arg)) {
// If an argument is a composer version, then we will alter
// the last project we saw, attaching this version to it.
// This allows us to handle 'a/b:1.0' and 'a/b 1.0' equivalently.
$keys = array_keys($projects);
$lastProject = array_pop($keys);
unset($projects[$lastProject]);
$projects[$lastProject] = $arg;
} elseif ($arg == 'global') {
// Make note if we see the 'global' command.
$globalMode = true;
} else {
// If we see any command other than 'global [require|update|remove]',
// then we will pass *all* of the arguments through to
// composer unchanged. We return an empty projects array
// to indicate that this should be a pass-through call
// to composer, rather than one or more calls to
// 'composer require' to install global projects.
if (!$globalMode || !in_array($arg, $cgrCommands)) {
return array('', array(), $argv);
}
// Remember which command we saw
$command = $arg;
}
}
return array($command, $projects, $composerArgs);
}