composer/composer — pull request #229 by simensen (2012-01-19 06:39:17+00:00)
Title: Make install method self contained

Experimental: Updated `install()` method to accept its Composer and input option dependencies as method arguments. The goal is to make `install()` self contained so that it can more easily be used in other places.

With these changes in place this method has no real need to be in a Command class any longer. Long-term I would like to explore lifting this method out of this class and putting it somewhere that is more easily reusable. (Like what happened to the Factory recently)

For a bit of context, I'm using this in my application as follows. I'm extending `InstallCommand` (renamed from `install` to `composer:install`) and `UpdateCommand` (renamed from `update` to `composer:update`). My Application does not extend `\Composer\Console\Application`, though, so a lot of the grunt work of creating the Composer object isn't being done. (No `$this->io` is created, for example...) Also, Composer support is a bundle/extension for my application, so it cannot be built directly into the application anyway. This was the best solution I was able to come up with.

```php
install(
Factory::create(new ConsoleIO($input, $output, $this->getApplication()->getHelperSet())),
$input,
$output,
false,
(Boolean)$input->getOption('dev'),
(Boolean)$input->getOption('dry-run'),
(Boolean)$input->getOption('verbose'),
(Boolean)$input->getOption('no-install-recommends'),
(Boolean)$input->getOption('install-suggests')
);
}
```

Even though the options at the end are the same as the provided Composer commands, I like the idea of giving that flexibility to the caller to decide where that comes from rather than having the `install()` method assume that the options are going to be sent a specific way. I could just as easily have hardcoded these options. (maybe I don't want to offer a --dry-run option or maybe I want to force --verbose to be on)