/** * Create a project from repo. * * @param string $package The package to install * * @return int */ public function createProject($package) { $io = $this->_io; $root = $this->_root; $factory = $this->_factory; $installerOptions = $this->_installerOptions; $function = $this->_wrap(function () use($package, $io, $root, $factory, $installerOptions) { $projectCreator = new CreateProjectCommand(); $input = new SymfonyInput(['--prefer-source' => $installerOptions['prefer-source'], '--prefer-dist' => $installerOptions['prefer-dist']], $projectCreator->getDefinition()); return $projectCreator->installProject($io, $factory->createConfig($io, $root), $package, $root, null, 'stable', false, false, false, null, false, false, false, false, false, false, $input); }); $result = $function(); if ($result !== 0) { throw new Exception\ComposerException('Composer failed to create project ' . $package . ': ' . $io->getLastError()); } return $this; }
/** * Fetch the project into the given directory. * * @return void * * @throws \RuntimeException When an error occurred. */ private function fetchProject() { $arguments = ['package' => $this->file->get(self::SETTING_PACKAGE), 'directory' => $this->tempDir, '--prefer-dist', '--no-dev', '--no-interaction']; if ($version = $this->file->get(self::SETTING_VERSION)) { $arguments['version'] = $version; } if ($repository = $this->file->get(self::SETTING_REPOSITORY_URL)) { $arguments['--repository-url'] = $repository; } $command = new CreateProjectCommand(); $input = new ArrayInput($arguments); $input->setInteractive(false); $command->setIO($this->getIO()); try { if (0 !== ($statusCode = $command->run($input, new TaskOutput($this)))) { throw new \RuntimeException('Command exit code was non zero ' . $statusCode); } } catch (\Exception $exception) { throw new \RuntimeException($exception->getMessage(), $exception->getCode(), $exception); } }