From bbf745f3e6160d08171042630bce31dbb91daf27 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 19 Feb 2012 12:00:14 +0100 Subject: [PATCH 1/8] Add command to install a package as a new project into a non-existant directory. This fetches the given package from packagist or a different packagist-source and installs it into a given path. --- .../Command/InstallProjectCommand.php | 121 ++++++++++++++++++ src/Composer/Console/Application.php | 1 + src/Composer/Installer/ProjectInstaller.php | 111 ++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 src/Composer/Command/InstallProjectCommand.php create mode 100644 src/Composer/Installer/ProjectInstaller.php diff --git a/src/Composer/Command/InstallProjectCommand.php b/src/Composer/Command/InstallProjectCommand.php new file mode 100644 index 000000000..3d38ea1a0 --- /dev/null +++ b/src/Composer/Command/InstallProjectCommand.php @@ -0,0 +1,121 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Command; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Output\OutputInterface; +use Composer\IO\IOInterface; +use Composer\Downloader\DownloadManager; +use Composer\Downloader; +use Composer\Repository\ComposerRepository; +use Composer\Installer\ProjectInstaller; + +/** + * Install a package as new project into new directory. + * + * @author Benjamin Eberlei + */ +class InstallProjectCommand extends Command +{ + protected function configure() + { + $this + ->setName('install-project') + ->setDescription('Install a package as new project into given directory.') + ->setDefinition(array( + new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), + new InputOption('packagist-url', null, InputOption::VALUE_REQUIRED, 'Pick a different packagist url to look for the package.'), + new InputArgument('package', InputArgument::REQUIRED), + new InputArgument('version', InputArgument::OPTIONAL), + new InputArgument('directory', InputArgument::OPTIONAL), + )) + ->setHelp(<<install-project command installs a given package into a new directory. +You can use this command to bootstrap new projects or setup a clean installation for +new developers of your project. + +php composer.phar install-project vendor/project intodirectory + +To setup a developer workable version you should create the project using the source +controlled code by appending the '--prefer-source' flag. + +To install a package from another packagist repository than the default one you +can pass the '--packagist-url=http://mypackagist.org' flag. + +EOT + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = $this->getApplication()->getIO(); + + return $this->installProject( + $io, + $input->getArgument('package'), + $input->getArgument('directory'), + $input->getArgument('version'), + (Boolean)$input->getOption('prefer-source'), + $input->getOption('packagist-url') + ); + } + + public function installProject(IOInterface $io, $packageName, $directory = null, $version = null, $preferSource = false, $packagistUrl = null) + { + $dm = $this->createDownloadManager($io); + if ($preferSource) { + $dm->setPreferSource(true); + } + + if ($packagistUrl === null) { + $sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org')); + } else { + $sourceRepo = new ComposerRepository(array('url' => $packagistUrl)); + } + $package = $sourceRepo->findPackage($packageName, $version); + if (!$package) { + throw new \InvalidArgumentException("Could not find package $packageName with version $version."); + } + + if ($directory === null) { + $parts = explode("/", $packageName); + $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); + } + + $projectInstaller = new ProjectInstaller($directory, $dm); + $projectInstaller->install($package); + + $io->write('Created new project directory for ' . $package->getName(), true); + $io->write('Next steps:', true); + $io->write('1. cd ' . $directory, true); + $io->write('2. composer install', true); + } + + protected function createDownloadManager(IOInterface $io) + { + $dm = new Downloader\DownloadManager(); + $dm->setDownloader('git', new Downloader\GitDownloader($io)); + $dm->setDownloader('svn', new Downloader\SvnDownloader($io)); + $dm->setDownloader('hg', new Downloader\HgDownloader($io)); + $dm->setDownloader('pear', new Downloader\PearDownloader($io)); + $dm->setDownloader('zip', new Downloader\ZipDownloader($io)); + $dm->setDownloader('tar', new Downloader\TarDownloader($io)); + $dm->setDownloader('phar', new Downloader\PharDownloader($io)); + + return $dm; + } +} + diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index fe6b6cb13..5802e2f86 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -107,6 +107,7 @@ class Application extends BaseApplication $this->add(new Command\DependsCommand()); $this->add(new Command\InitCommand()); $this->add(new Command\InstallCommand()); + $this->add(new Command\InstallProjectCommand()); $this->add(new Command\UpdateCommand()); $this->add(new Command\SearchCommand()); $this->add(new Command\ValidateCommand()); diff --git a/src/Composer/Installer/ProjectInstaller.php b/src/Composer/Installer/ProjectInstaller.php new file mode 100644 index 000000000..da9236a97 --- /dev/null +++ b/src/Composer/Installer/ProjectInstaller.php @@ -0,0 +1,111 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Installer; + +use Composer\DependencyResolver\Operation\OperationInterface; +use Composer\Package\PackageInterface; +use Composer\Downloader\DownloadManager; + +/** + * Project Installer is used to install a single package into a directory as + * root project. + * + * @author Benjamin Eberlei + */ +class ProjectInstaller implements InstallerInterface +{ + private $installPath; + private $downloadManager; + + public function __construct($installPath, DownloadManager $dm) + { + $this->installPath = $installPath; + $this->downloadManager = $dm; + } + + /** + * Decides if the installer supports the given type + * + * @param string $packageType + * @return Boolean + */ + public function supports($packageType) + { + return true; + } + + /** + * Checks that provided package is installed. + * + * @param PackageInterface $package package instance + * + * @return Boolean + */ + public function isInstalled(PackageInterface $package) + { + return false; + } + + /** + * Installs specific package. + * + * @param PackageInterface $package package instance + */ + public function install(PackageInterface $package) + { + $installPath = $this->installPath; + if (file_exists($installPath)) { + throw new \InvalidArgumentException("Project directory $installPath already exists."); + } + if (!file_exists(dirname($installPath))) { + throw new \InvalidArgumentException("Project root " . dirname($installPath) . " does not exist."); + } + mkdir($installPath, 0777); + $this->downloadManager->download($package, $installPath); + } + + /** + * Updates specific package. + * + * @param PackageInterface $initial already installed package version + * @param PackageInterface $target updated version + * + * @throws InvalidArgumentException if $from package is not installed + */ + public function update(PackageInterface $initial, PackageInterface $target) + { + throw new \InvalidArgumentException("not supported"); + } + + /** + * Uninstalls specific package. + * + * @param PackageInterface $package package instance + */ + public function uninstall(PackageInterface $package) + { + throw new \InvalidArgumentException("not supported"); + } + + /** + * Returns the installation path of a package + * + * @param PackageInterface $package + * @return string path + */ + public function getInstallPath(PackageInterface $package) + { + return $this->installPath; + } +} + From 1c67633c7087da6fa3f28e0fae0737e2f423e7ab Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 19 Feb 2012 12:08:38 +0100 Subject: [PATCH 2/8] Refactored downloader code and made packagist configuration flexible and validated. --- .../Command/InstallProjectCommand.php | 22 ++++++++----------- src/Composer/Factory.php | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Composer/Command/InstallProjectCommand.php b/src/Composer/Command/InstallProjectCommand.php index 3d38ea1a0..6d493c5f2 100644 --- a/src/Composer/Command/InstallProjectCommand.php +++ b/src/Composer/Command/InstallProjectCommand.php @@ -17,8 +17,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; use Composer\IO\IOInterface; -use Composer\Downloader\DownloadManager; -use Composer\Downloader; +use Composer\Factory; use Composer\Repository\ComposerRepository; use Composer\Installer\ProjectInstaller; @@ -82,9 +81,14 @@ EOT if ($packagistUrl === null) { $sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org')); - } else { + } else if (substr($packagistUrl, -5) === ".json") { + $sourceRepo = new FilesystemRepository($packagistUrl); + } else if (strpos($packagistUrl, 'http') === 0) { $sourceRepo = new ComposerRepository(array('url' => $packagistUrl)); + } else { + throw new \InvalidArgumentException("Invalid Packagist Url given. Has to be a .json file or an http url."); } + $package = $sourceRepo->findPackage($packageName, $version); if (!$package) { throw new \InvalidArgumentException("Could not find package $packageName with version $version."); @@ -106,16 +110,8 @@ EOT protected function createDownloadManager(IOInterface $io) { - $dm = new Downloader\DownloadManager(); - $dm->setDownloader('git', new Downloader\GitDownloader($io)); - $dm->setDownloader('svn', new Downloader\SvnDownloader($io)); - $dm->setDownloader('hg', new Downloader\HgDownloader($io)); - $dm->setDownloader('pear', new Downloader\PearDownloader($io)); - $dm->setDownloader('zip', new Downloader\ZipDownloader($io)); - $dm->setDownloader('tar', new Downloader\TarDownloader($io)); - $dm->setDownloader('phar', new Downloader\PharDownloader($io)); - - return $dm; + $factory = new Factory(); + return $factory->createDownloadManager($io); } } diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index cf70c4c74..61284acae 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -138,7 +138,7 @@ class Factory $rm->addRepository(new Repository\ComposerRepository(array('url' => 'http://packagist.org'))); } - protected function createDownloadManager(IOInterface $io) + public function createDownloadManager(IOInterface $io) { $dm = new Downloader\DownloadManager(); $dm->setDownloader('git', new Downloader\GitDownloader($io)); From f60fe5622aa1f32ae6eb41b6e138f7e5c87e4174 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 19 Feb 2012 12:15:39 +0100 Subject: [PATCH 3/8] Add missing use stmt. --- src/Composer/Command/InstallProjectCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Composer/Command/InstallProjectCommand.php b/src/Composer/Command/InstallProjectCommand.php index 6d493c5f2..48227f8bb 100644 --- a/src/Composer/Command/InstallProjectCommand.php +++ b/src/Composer/Command/InstallProjectCommand.php @@ -19,6 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Composer\IO\IOInterface; use Composer\Factory; use Composer\Repository\ComposerRepository; +use Composer\Repository\FilesystemRepository; use Composer\Installer\ProjectInstaller; /** From 23719b3b1d2d562f1c02eca3c96d4d9496815b66 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 19 Feb 2012 12:17:10 +0100 Subject: [PATCH 4/8] Rename packagist url to repository url --- .../Command/InstallProjectCommand.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Composer/Command/InstallProjectCommand.php b/src/Composer/Command/InstallProjectCommand.php index 48227f8bb..c03cfeb0c 100644 --- a/src/Composer/Command/InstallProjectCommand.php +++ b/src/Composer/Command/InstallProjectCommand.php @@ -36,7 +36,7 @@ class InstallProjectCommand extends Command ->setDescription('Install a package as new project into given directory.') ->setDefinition(array( new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), - new InputOption('packagist-url', null, InputOption::VALUE_REQUIRED, 'Pick a different packagist url to look for the package.'), + new InputOption('repository-url', null, InputOption::VALUE_REQUIRED, 'Pick a different repository url to look for the package.'), new InputArgument('package', InputArgument::REQUIRED), new InputArgument('version', InputArgument::OPTIONAL), new InputArgument('directory', InputArgument::OPTIONAL), @@ -51,8 +51,8 @@ new developers of your project. To setup a developer workable version you should create the project using the source controlled code by appending the '--prefer-source' flag. -To install a package from another packagist repository than the default one you -can pass the '--packagist-url=http://mypackagist.org' flag. +To install a package from another repository repository than the default one you +can pass the '--repository-url=http://myrepository.org' flag. EOT ) @@ -69,25 +69,25 @@ EOT $input->getArgument('directory'), $input->getArgument('version'), (Boolean)$input->getOption('prefer-source'), - $input->getOption('packagist-url') + $input->getOption('repository-url') ); } - public function installProject(IOInterface $io, $packageName, $directory = null, $version = null, $preferSource = false, $packagistUrl = null) + public function installProject(IOInterface $io, $packageName, $directory = null, $version = null, $preferSource = false, $repositoryUrl = null) { $dm = $this->createDownloadManager($io); if ($preferSource) { $dm->setPreferSource(true); } - if ($packagistUrl === null) { + if ($repositoryUrl === null) { $sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org')); - } else if (substr($packagistUrl, -5) === ".json") { - $sourceRepo = new FilesystemRepository($packagistUrl); - } else if (strpos($packagistUrl, 'http') === 0) { - $sourceRepo = new ComposerRepository(array('url' => $packagistUrl)); + } else if (substr($repositoryUrl, -5) === ".json") { + $sourceRepo = new FilesystemRepository($repositoryUrl); + } else if (strpos($repositoryUrl, 'http') === 0) { + $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl)); } else { - throw new \InvalidArgumentException("Invalid Packagist Url given. Has to be a .json file or an http url."); + throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url."); } $package = $sourceRepo->findPackage($packageName, $version); From 62bdaaf4087cdb2cac3292131438cb80edd79db2 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 19 Feb 2012 12:31:58 +0100 Subject: [PATCH 5/8] Add docs --- doc/create-projects.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 doc/create-projects.md diff --git a/doc/create-projects.md b/doc/create-projects.md new file mode 100644 index 000000000..4a373dbac --- /dev/null +++ b/doc/create-projects.md @@ -0,0 +1,16 @@ +# Create Projects + +You can use Composer to create new projects from existing packages. There are several applications for this: + +1. You can deploy application packages. +2. You can check out any package and start developing on patches for example. +3. Projects with multiple developers can use this feature to bootstrap the initial application for development. + +To create a new project using composer you can use the "install-project", pass it a package name + version and a directory to create the project in. The directory is not allowed to exist, it will be created during installation. + + php composer.phar install-project doctrine/orm 2.2.0 /path/to/new-project + +By default the command checks for the packages on packagist.org. To change this behavior you can use the --repository-url parameter and either point it to an HTTP url for your own packagist repository or to a packages.json file. + +If you want to get a development version of the code directly checked out from version control you have to add the --prefer-source parameter. + From db64917a83bdd0ff56f3f7d75cc7aac736b14d89 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 19 Feb 2012 12:42:00 +0100 Subject: [PATCH 6/8] Renamed install-project to create-project to differentiate from just "install". --- doc/create-projects.md | 6 +++--- ...rojectCommand.php => CreateProjectCommand.php} | 15 ++++++++------- src/Composer/Console/Application.php | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) rename src/Composer/Command/{InstallProjectCommand.php => CreateProjectCommand.php} (89%) diff --git a/doc/create-projects.md b/doc/create-projects.md index 4a373dbac..0cf187959 100644 --- a/doc/create-projects.md +++ b/doc/create-projects.md @@ -1,14 +1,14 @@ # Create Projects -You can use Composer to create new projects from existing packages. There are several applications for this: +You can use Composer to create new projects from an existing package. There are several applications for this: 1. You can deploy application packages. 2. You can check out any package and start developing on patches for example. 3. Projects with multiple developers can use this feature to bootstrap the initial application for development. -To create a new project using composer you can use the "install-project", pass it a package name + version and a directory to create the project in. The directory is not allowed to exist, it will be created during installation. +To create a new project using composer you can use the "create-project", pass it a package name + version and a directory to create the project in. The directory is not allowed to exist, it will be created during installation. - php composer.phar install-project doctrine/orm 2.2.0 /path/to/new-project + php composer.phar create-project doctrine/orm 2.2.0 /path/to/new-project By default the command checks for the packages on packagist.org. To change this behavior you can use the --repository-url parameter and either point it to an HTTP url for your own packagist repository or to a packages.json file. diff --git a/src/Composer/Command/InstallProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php similarity index 89% rename from src/Composer/Command/InstallProjectCommand.php rename to src/Composer/Command/CreateProjectCommand.php index c03cfeb0c..b1d1c9854 100644 --- a/src/Composer/Command/InstallProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -27,13 +27,13 @@ use Composer\Installer\ProjectInstaller; * * @author Benjamin Eberlei */ -class InstallProjectCommand extends Command +class CreateProjectCommand extends Command { protected function configure() { $this - ->setName('install-project') - ->setDescription('Install a package as new project into given directory.') + ->setName('create-project') + ->setDescription('Create new project from a package into given directory.') ->setDefinition(array( new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), new InputOption('repository-url', null, InputOption::VALUE_REQUIRED, 'Pick a different repository url to look for the package.'), @@ -42,11 +42,12 @@ class InstallProjectCommand extends Command new InputArgument('directory', InputArgument::OPTIONAL), )) ->setHelp(<<install-project command installs a given package into a new directory. -You can use this command to bootstrap new projects or setup a clean installation for -new developers of your project. +The create-project command creates a new project from a given +package into a new directory. You can use this command to bootstrap new +projects or setup a clean version-controlled installation +for developers of your project. -php composer.phar install-project vendor/project intodirectory +php composer.phar create-project vendor/project intodirectory To setup a developer workable version you should create the project using the source controlled code by appending the '--prefer-source' flag. diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 5802e2f86..e836d65c8 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -107,7 +107,7 @@ class Application extends BaseApplication $this->add(new Command\DependsCommand()); $this->add(new Command\InitCommand()); $this->add(new Command\InstallCommand()); - $this->add(new Command\InstallProjectCommand()); + $this->add(new Command\CreateProjectCommand()); $this->add(new Command\UpdateCommand()); $this->add(new Command\SearchCommand()); $this->add(new Command\ValidateCommand()); From 24de082fd51a8099e8f4bcfac66426199b241193 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 19 Feb 2012 12:45:37 +0100 Subject: [PATCH 7/8] Refactored --- doc/create-projects.md | 14 ++++++++++---- src/Composer/Command/CreateProjectCommand.php | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/doc/create-projects.md b/doc/create-projects.md index 0cf187959..c1e220139 100644 --- a/doc/create-projects.md +++ b/doc/create-projects.md @@ -1,16 +1,22 @@ # Create Projects -You can use Composer to create new projects from an existing package. There are several applications for this: +You can use Composer to create new projects from an existing package. +There are several applications for this: 1. You can deploy application packages. 2. You can check out any package and start developing on patches for example. 3. Projects with multiple developers can use this feature to bootstrap the initial application for development. -To create a new project using composer you can use the "create-project", pass it a package name + version and a directory to create the project in. The directory is not allowed to exist, it will be created during installation. +To create a new project using composer you can use the "create-project", +pass it a package name + version and a directory to create the project in. +The directory is not allowed to exist, it will be created during installation. php composer.phar create-project doctrine/orm 2.2.0 /path/to/new-project -By default the command checks for the packages on packagist.org. To change this behavior you can use the --repository-url parameter and either point it to an HTTP url for your own packagist repository or to a packages.json file. +By default the command checks for the packages on packagist.org. To change this behavior +you can use the --repository-url parameter and either point it to an HTTP url +for your own packagist repository or to a packages.json file. -If you want to get a development version of the code directly checked out from version control you have to add the --prefer-source parameter. +If you want to get a development version of the code directly checked out +from version control you have to add the --prefer-source parameter. diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index b1d1c9854..6cbf0f3fc 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -81,11 +81,11 @@ EOT $dm->setPreferSource(true); } - if ($repositoryUrl === null) { + if (null === $repositoryUrl) { $sourceRepo = new ComposerRepository(array('url' => 'http://packagist.org')); - } else if (substr($repositoryUrl, -5) === ".json") { + } elseif (".json" === substr($repositoryUrl, -5)) { $sourceRepo = new FilesystemRepository($repositoryUrl); - } else if (strpos($repositoryUrl, 'http') === 0) { + } elseif (0 === strpos($repositoryUrl, 'http')) { $sourceRepo = new ComposerRepository(array('url' => $repositoryUrl)); } else { throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url."); @@ -96,7 +96,7 @@ EOT throw new \InvalidArgumentException("Could not find package $packageName with version $version."); } - if ($directory === null) { + if (null === $directory) { $parts = explode("/", $packageName); $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); } From 36ccd38aa75d7ec9afb820745b49f875022df7f4 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 27 Feb 2012 20:52:41 +0100 Subject: [PATCH 8/8] Directly install dependencies --- src/Composer/Command/CreateProjectCommand.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 6cbf0f3fc..5677a0553 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -15,6 +15,7 @@ namespace Composer\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; use Composer\IO\IOInterface; use Composer\Factory; @@ -66,6 +67,7 @@ EOT return $this->installProject( $io, + $this->getInstallCommand($input, $output), $input->getArgument('package'), $input->getArgument('directory'), $input->getArgument('version'), @@ -74,7 +76,16 @@ EOT ); } - public function installProject(IOInterface $io, $packageName, $directory = null, $version = null, $preferSource = false, $repositoryUrl = null) + protected function getInstallCommand($input, $output) + { + $app = $this->getApplication(); + return function() use ($app, $input, $output) { + $newInput = new ArrayInput(array('command' => 'install')); + $app->doRUn($newInput, $output); + }; + } + + public function installProject(IOInterface $io, $installCommand, $packageName, $directory = null, $version = null, $preferSource = false, $repositoryUrl = null) { $dm = $this->createDownloadManager($io); if ($preferSource) { @@ -101,13 +112,13 @@ EOT $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); } + $io->write('Installing ' . $package->getName() . ' as new project.', true); $projectInstaller = new ProjectInstaller($directory, $dm); $projectInstaller->install($package); - $io->write('Created new project directory for ' . $package->getName(), true); - $io->write('Next steps:', true); - $io->write('1. cd ' . $directory, true); - $io->write('2. composer install', true); + $io->write('Created project into directory ' . $directory . '', true); + chdir($directory); + $installCommand(); } protected function createDownloadManager(IOInterface $io)