function composer_ALL(Web $w) { echo "<pre>" . file_get_contents(ROOT_PATH . '/log/composer.log') . "</pre>"; // Collect dependencies $dependencies_array = array(); foreach ($w->modules() as $module) { $dependencies = Config::get("{$module}.dependencies"); if (!empty($dependencies)) { $dependencies_array = array_merge($dependencies, $dependencies_array); } } $json_obj = array(); $json_obj["config"] = array(); $json_obj["config"]["vendor-dir"] = 'composer/vendor'; $json_obj["config"]["cache-dir"] = 'composer/cache'; $json_obj["config"]["bin-dir"] = 'composer/bin'; $json_obj["require"] = $dependencies_array; // Need to change dir so composer can find the json file chdir(SYSTEM_PATH); // Create the JSON file file_put_contents(SYSTEM_PATH . "/composer.json", json_encode($json_obj, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_FORCE_OBJECT)); //Create the commands $input = new ArrayInput(array('command' => 'update', '--prefer-dist' => 'true')); $filestream = new StreamOutput(fopen(ROOT_PATH . '/log/composer.log', 'w')); //Create the application and run it with the commands $application = new Application(); $exitcode = $application->run($input, $filestream); // Change dir back to root chdir(ROOT_PATH); // This doesn't happen for some reason $w->msg("Composer update return exit code " . $exitcode . " (0 is OK)<br/>Check the /log/composer.log for output", "/admin"); }
/** * Run 'composer remove' * * @param array $packages * @return void */ public function remove(array $packages) { $this->composerApp->resetComposer(); $this->composerApp->setAutoExit(false); $vendor = (include $this->directoryList->getPath(DirectoryList::CONFIG) . '/vendor_path.php'); $this->composerApp->run(new ArrayInput(['command' => 'remove', 'packages' => $packages, '--working-dir' => $this->directoryList->getRoot() . '/' . $vendor . '/..'])); }
/** * Updates composer dependencies. */ public function updateDependencies() { $container = InnomaticContainer::instance('\\Innomatic\\Core\\InnomaticContainer'); // Keep track of the current directory $previousDirectory = getcwd(); // Retrieve the Innomatic Platform root directory $platformHome = RootContainer::instance('\\Innomatic\\Core\\RootContainer')->getPlatformHome(); // Switch current directory to the Innomatic Platform root chdir($platformHome); // Call composer install command $input = new ArrayInput(array('command' => 'update')); if ($container->getInterface() == InnomaticContainer::INTERFACE_CONSOLE) { $output = new ConsoleOutput(); } else { $output = new BufferedOutput(); } $application = new ComposerApplication(); // Prevent application run method from exiting the script $application->setAutoExit(false); $application->run($input, $output); // Switch back to the previous current directory chdir($previousDirectory); // Switch back to the standard Innomatic PHP error handler set_error_handler(array($container, 'errorHandler')); }
/** * @return Application */ protected function createComposerApplication() { $composer = new Application(); $composer->setAutoExit(false); $composer->setCatchExceptions(false); return $composer; }
/** * Standard Running the Composer Command * * @return object */ public function run() { // Run the Composer command. $application = new Application(); $application->setAutoExit(false); $application->run(); return $this->loader; }
private function composerInstall() { $this->io->writeln("Running Composer install:", 'green'); putenv('COMPOSER_HOME=' . $this->application()->basePath() . '/vendor/bin/composer'); $input = new ArrayInput(['command' => 'install']); $composer = new Application(); $composer->setAutoExit(false); $composer->run($input); $this->io->writeln(); }
public function update($name) { $app = new Application(); $app->setAutoExit(false); $input = new ArrayInput(['update', 'packages' => [$name]]); $input->setInteractive(false); $output = new BufferedOutput(); $app->run($input, $output); return $output->fetch(); }
function testRunCommand() { $inputData = ['command' => 'update', MagentoComposerApplication::COMPOSER_WORKING_DIR => '.']; $this->composerApplication->expects($this->once())->method('resetComposer'); $this->inputFactory->expects($this->once())->method('create')->with($inputData); $this->consoleOutput->expects($this->once())->method('fetch')->willReturn('Nothing to update'); $this->composerApplication->expects($this->once())->method('run')->willReturn(0); $message = $this->application->runComposerCommand($inputData); $this->assertEquals('Nothing to update', $message); }
/** * Rebuilds the root package, then calls 'composer update'. */ public static function update(Event $event) { $package_manager = self::getPackageManager(); $package_manager->rebuildRootPackage(); // Change the requested command to 'update', and rerun composer. $command_index = array_search('drupal-update', $_SERVER['argv']); $_SERVER['argv'][$command_index] = 'update'; $application = new Application(); $application->run(); }
private function checkComposer() { $this->io->writeln("Checking Composer status:", 'green'); //putenv('COMPOSER_HOME=' . $this->application()->basePath() . '/vendor/bin/composer/composer/src/'); $input = new ArrayInput(['command' => 'update', '--dry-run' => true]); $composer = new Application(); $composer->setAutoExit(false); $composer->run($input); $this->io->writeln(); }
/** * @see \WsdlToPhp\PackageGenerator\File\AbstractFile::writeFile() * @return int|bool */ protected function writeFile() { $composer = new Application(); $composer->setAutoExit(false); $composer->run(new ArrayInput(array('command' => 'init', '--verbose' => true, '--no-interaction' => true, '--name' => $this->getGenerator()->getOptionComposerName(), '--description' => sprintf('Package generated from %s using wsdltophp/packagegenerator', $this->getGenerator()->getWsdl()->getName()), '--require' => array('php:>=5.3.3', 'ext-soap:*', 'wsdltophp/packagebase:dev-master'), '--working-dir' => $this->getGenerator()->getOptionDestination()))); $this->addAutoloadToComposerJson(); if ($this->getRunComposerUpdate() === true) { return $composer->run(new ArrayInput(array('command' => 'update', '--verbose' => true, '--optimize-autoloader' => true, '--no-dev' => true, '--working-dir' => $this->getGenerator()->getOptionDestination()))); } return 1; }
public function diagnose() { $instance = WpComposer::Instance(); $instance->recursiveExecution(function ($path, $data, $is_plugin, $is_theme) { WP_CLI::line(sprintf('Starting to process %s', end(explode('/', $path)))); $_SERVER['argv'] = array('composer', 'diagnose'); // Run the Composer command. $application = new Application(); $application->setAutoExit(false); $application->run(); WP_CLI::success('Finished processing'); }); }
protected function setUp() { parent::setUp(); $this->application = static::getMock(Application::class); $this->sut = $this->getSut(); $command = static::getMockBuilder(Command::class)->disableOriginalConstructor()->getMock(); $command->expects(static::any())->method('getApplication')->willReturn($this->application); $command->expects(static::any())->method('getName')->willReturn('mock command'); $helperSet = new HelperSet(); $helperSet->setCommand($command); $this->sut->setHelperSet($helperSet); $this->application->setHelperSet($helperSet); }
public function handleUpdate() { // Composer\Factory::getHomeDir() method // needs COMPOSER_HOME environment variable set putenv('COMPOSER_HOME=' . DIR_ROOT . '/vendor/bin/composer'); $input = new ArrayInput(['command' => 'update']); $output = new ConsoleOutput(); $application = new Application(); $application->setAutoExit(false); // prevent `$application->run` method from exitting the script $application->run($input, $output); $this->flashMessage("Update has been successfully done!", "success"); $this->redirect('this'); }
/** * @param string $commandName * @param array|string $arguments * @param array|string $parameters **/ protected function runComposerCommand($commandName, $parameters = [], $arguments = []) { $arguments = (array) $arguments; $parameters = (array) $parameters; $input = new ArrayInput(array_merge(['command' => $commandName], $this->config['defaultParameters'], $parameters, $arguments)); // this is ugly but require doesn't seem to work otherwise if ($commandName === 'require') { exec('composer ' . $input); } else { $composer = new Application(); $composer->setAutoExit(false); $composer->run($input); } }
public function ensureNoDevWarning($command) { $application = new Application(); $application->add(new \Composer\Command\SelfUpdateCommand()); $inputMock = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface'); $outputMock = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface'); $inputMock->expects($this->once())->method('getFirstArgument')->will($this->returnValue($command)); $outputMock->expects($this->never())->method("writeln"); if (!defined('COMPOSER_DEV_WARNING_TIME')) { define('COMPOSER_DEV_WARNING_TIME', time() - 1); } $this->setExpectedException('RuntimeException'); $application->doRun($inputMock, $outputMock); }
/** * Overridden so that the application doesn't expect the command * name to be the first argument. */ public function getDefinition() { $inputDefinition = parent::getDefinition(); // clear out the normal first argument, which is the command name $inputDefinition->setArguments(); return $inputDefinition; }
/** * Checks dependencies to package(s), returns array of dependencies in the format of * 'package A' => [array of package names depending on package A] * If $excludeSelf is set to true, items in $packages will be excluded in all * "array of package names depending on package A" * * @param string[] $packages * @param bool $excludeSelf * @return string[] */ public function checkDependencies(array $packages, $excludeSelf = false) { $this->composerApp->setAutoExit(false); $dependencies = []; foreach ($packages as $package) { $buffer = new BufferedOutput(); $this->composerApp->resetComposer(); $this->composerApp->run(new ArrayInput(['command' => 'depends', '--working-dir' => $this->directoryList->getRoot(), 'package' => $package]), $buffer); $dependingPackages = $this->parseComposerOutput($buffer->fetch()); if ($excludeSelf === true) { $dependingPackages = array_values(array_diff($dependingPackages, $packages)); } $dependencies[$package] = $dependingPackages; } return $dependencies; }
public function ensureNoDevWarning($command) { $application = new Application(); $application->add(new \Composer\Command\SelfUpdateCommand()); $inputMock = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface'); $outputMock = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface'); $index = 0; $inputMock->expects($this->at($index++))->method('hasParameterOption')->with($this->equalTo('--no-plugins'))->will($this->returnValue(true)); $inputMock->expects($this->at($index++))->method('getParameterOption')->with($this->equalTo(array('--working-dir', '-d')))->will($this->returnValue(false)); $inputMock->expects($this->at($index++))->method('getFirstArgument')->will($this->returnValue('list')); $outputMock->expects($this->never())->method("writeln"); if (!defined('COMPOSER_DEV_WARNING_TIME')) { define('COMPOSER_DEV_WARNING_TIME', time() - 1); } $application->doRun($inputMock, $outputMock); }
/** * Initializes all the composer commands */ protected function getDefaultCommands() { $commands = parent::getDefaultCommands(); $commands[] = new Command\ClientCommand(); $commands[] = new Command\PackageCommand(); return $commands; }
private function setup() { $httpOk = array(200, 301, 302); umask(00); putenv('COMPOSER_HOME=' . $this->app['resources']->getPath('cache') . '/composer'); // Since we output JSON most of the time, we do _not_ want notices or warnings. // Set the error reporting before initializing Composer, to suppress them. $oldErrorReporting = error_reporting(E_ERROR); // Create the Composer application object $this->composerapp = new ComposerApp(); // Don't automatically exit after a command execution $this->composerapp->setAutoExit(false); // re-set error reporting to the value it should be. error_reporting($oldErrorReporting); if (!is_file($this->packageFile)) { $this->execute('init'); } // Check to see if composer.json is writable if (is_file($this->packageFile) && !is_writable($this->packageFile)) { $this->messages[] = sprintf("The file '%s' is not writable. You will not be able to use this feature without changing the permissions.", $this->packageFile); $this->offline = true; } // Ping the extensions server to confirm connection $response = $this->ping($this->app['extend.site'], 'ping', true); if (!in_array($response, $httpOk)) { $this->messages[] = $this->app['extend.site'] . ' is unreachable.'; $this->offline = true; } if ($this->offline) { $this->messages[] = 'Unable to install/update extensions!'; return false; } $this->execute('config repositories.bolt composer ' . $this->app['extend.site'] . 'satis/'); $jsonfile = file_get_contents($this->packageFile); $json = json_decode($jsonfile); $json->repositories->packagist = false; $json->{'minimum-stability'} = $this->app['config']->get('general/extensions/stability', 'stable'); $json->{'prefer-stable'} = true; $json->config = array('discard-changes' => true, 'preferred-install' => 'dist'); $basePackage = "bolt/bolt"; $json->provide = new \stdClass(); $json->provide->{$basePackage} = $this->app['bolt_version']; $json->scripts = array('post-package-install' => "Bolt\\Composer\\ExtensionInstaller::handle", 'post-package-update' => "Bolt\\Composer\\ExtensionInstaller::handle"); $pathToWeb = $this->app['resources']->findRelativePath($this->app['resources']->getPath('extensions'), $this->app['resources']->getPath('web')); $json->extra = array('bolt-web-path' => $pathToWeb); $json->autoload = array('files' => array("installer.php")); // Write out the file, but only if it's actually changed, and if it's writable. if ($jsonfile !== json_encode($json, 128 | 64)) { file_put_contents($this->packageFile, json_encode($json, 128 | 64)); } try { $json = json_decode(file_get_contents($this->packageRepo)); $this->available = $json->packages; } catch (\Exception $e) { $this->messages[] = Trans::__('The Bolt extensions Repo at %repository% is currently unavailable. Check your connection and try again shortly.', array('%repository%' => $this->packageRepo)); $this->available = array(); } }
/** * Run this composer wrapper as a command-line application. * * @param string $input command line arguments * @param object $output output object * @return integer 0 if everything went fine, or an error code * @see http://api.symfony.com/2.2/Symfony/Component/Console/Application.html#method_run */ public function run($input = '', $output = null) { $this->loadComposerPhar(false); if (!$this->application) { $this->application = new \Composer\Console\Application(); $this->application->setAutoExit(false); } $cli_args = is_string($input) && !empty($input) ? new \Symfony\Component\Console\Input\StringInput($input) : null; return $this->application->run($cli_args, $output); }
/** * Run this composer wrapper as a command-line application. * * @param string $input command line arguments * @param object $output output object * @return integer 0 if everything went fine, or an error code * @see http://api.symfony.com/2.2/Symfony/Component/Console/Application.html#method_run */ public function run($input = '', $output = null) { $this->loadComposerPhar(false); if (!$this->application) { $this->application = new \Composer\Console\Application(); $this->application->setAutoExit(false); } $cli_args = is_string($input) && !empty($input) ? new \Symfony\Component\Console\Input\StringInput($input) : null; $argv0 = $_SERVER['argv'][0]; $this->fixSelfupdate($cli_args); $exitcode = $this->application->run($cli_args, $output); $_SERVER['argv'][0] = $argv0; return $exitcode; }
/** * Run composer command * * @param array $commandParams * @return bool * @throws \RuntimeException */ protected function runComposerCommand(array $commandParams) { $input = $this->consoleArrayInputFactory->create($commandParams); $this->consoleApplication->setAutoExit(false); putenv('COMPOSER_HOME=' . $this->composerConfigFileDir . '/' . self::COMPOSER_HOME_DIR); putenv('COMPOSER=' . $this->composerConfigFileDir . '/composer.json'); $exitCode = $this->consoleApplication->run($input, $this->consoleOutput); $output = $this->consoleOutput->fetch(); if ($exitCode) { $commandParamsString = json_encode($commandParams, JSON_UNESCAPED_SLASHES); throw new \RuntimeException(sprintf('Command "%s"%s failed: %s', $commandParams['command'], $commandParamsString, $output)); } return $output; }
/** * Fires the job. * * @param $job * @param array $data * @throws \Exception */ public function fire($job, $data) { echo 'Running: OxygenModule\\Marketplace\\Installer\\ComposerInstallJob' . "\n"; // Composer\Factory::getHomeDir() method // needs COMPOSER_HOME environment variable set putenv('COMPOSER=' . base_path() . '/composer.json'); putenv('COMPOSER_HOME=' . base_path() . '/.composer'); $log = $this->config->get('oxygen.mod-marketplace.install.log'); $progress = $this->config->get('oxygen.mod-marketplace.install.progress'); foreach ([$log, $progress] as $file) { $this->files->delete($file); if (!$this->files->exists(dirname($file))) { $this->files->makeDirectory(dirname($file)); } } $input = new ArrayInput($this->config->get('oxygen.mod-marketplace.install.command')); $this->output = new StreamOutput(fopen($log, 'a', false), OutputInterface::VERBOSITY_DEBUG); $this->progress = new FileProgress($progress, $this->output); $this->progress->section('Beginning Installation'); $this->progress->indeterminate(); $this->progress->notification('Installation Started'); $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); try { $application->run($input, $this->output, $this->progress); $this->events->fire('oxygen.marketplace.postUpdate', [$this->progress, $this->output]); $this->progress->notification('Installation Complete'); $this->progress->section('Complete'); $this->progress->stopPolling(); $job->delete(); } catch (Exception $e) { $this->progress->notification($e->getMessage(), 'failed'); $this->progress->stopPolling(); throw $e; } }
public static function install($packages) { // Don't proceed if packages haven't changed. if ($packages == self::dump()) { return false; } putenv('COMPOSER_HOME=' . __DIR__ . '/../../vendor/bin/composer'); self::createComposerJson($packages); chdir(storage_dir()); // Setup composer output formatter $stream = fopen('php://temp', 'w+'); $output = new StreamOutput($stream); // Programmatically run `composer install` $application = new Application(); $application->setAutoExit(false); $code = $application->run(new ArrayInput(array('command' => 'install')), $output); // remove composer.lock if (file_exists(storage_dir() . 'composer.lock')) { unlink(storage_dir() . 'composer.lock'); } // rewind stream to read full contents rewind($stream); return stream_get_contents($stream); }
public function execute(IOStream $io) { $io->writeln('Optimizing Core Framework...', 'green'); if ($this->getOptions('all') || $this->getOptions('a')) { putenv('COMPOSER_HOME=' . $this->application()->basePath() . '/vendor/bin/composer'); $input = new ArrayInput(['command' => 'clearcache']); $composer = new Application(); $composer->setAutoExit(false); $composer->run($input); $input = new ArrayInput(['command' => 'dumpautoload']); $composer = new Application(); $composer->setAutoExit(false); $composer->run($input); } $cache = $this->application()->getCache(); $config = $this->application()->getConfig(); $router = $this->application()->getRouter(); $cache->delete('framework.conf'); $cache->delete('routes'); $router->loadRoutes(); $router->cacheRoutes(); $cache->put('framework.conf', $config->all(), $config->get('app.ttl', 60)); $io->writeln('Core Framework Application Optimized successfully!', 'green'); }
/** * Runs composer command * * @param array $commandParams * @param string|null $workingDir * @return bool * @throws \RuntimeException */ public function runComposerCommand(array $commandParams, $workingDir = null) { $this->consoleApplication->resetComposer(); if ($workingDir) { $commandParams[self::COMPOSER_WORKING_DIR] = $workingDir; } else { $commandParams[self::COMPOSER_WORKING_DIR] = dirname($this->composerJson); } $input = $this->consoleArrayInputFactory->create($commandParams); $exitCode = $this->consoleApplication->run($input, $this->consoleOutput); if ($exitCode) { throw new \RuntimeException(sprintf('Command "%s" failed: %s', $commandParams['command'], $this->consoleOutput->fetch())); } return $this->consoleOutput->fetch(); }
/** * @dataProvider getIntegrationTests */ public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectOutput, $expect) { if ($condition) { eval('$res = '.$condition.';'); if (!$res) { $this->markTestSkipped($condition); } } $output = null; $io = $this->getMock('Composer\IO\IOInterface'); $io->expects($this->any()) ->method('write') ->will($this->returnCallback(function ($text, $newline) use (&$output) { $output .= $text . ($newline ? "\n":""); })); $composer = FactoryMock::create($io, $composerConfig); $jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock(); $jsonMock->expects($this->any()) ->method('read') ->will($this->returnValue($installed)); $jsonMock->expects($this->any()) ->method('exists') ->will($this->returnValue(true)); $repositoryManager = $composer->getRepositoryManager(); $repositoryManager->setLocalRepository(new InstalledFilesystemRepositoryMock($jsonMock)); $lockJsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock(); $lockJsonMock->expects($this->any()) ->method('read') ->will($this->returnValue($lock)); $lockJsonMock->expects($this->any()) ->method('exists') ->will($this->returnValue(true)); if ($expectLock) { $actualLock = array(); $lockJsonMock->expects($this->atLeastOnce()) ->method('write') ->will($this->returnCallback(function ($hash, $options) use (&$actualLock) { // need to do assertion outside of mock for nice phpunit output // so store value temporarily in reference for later assetion $actualLock = $hash; })); } $locker = new Locker($lockJsonMock, $repositoryManager, $composer->getInstallationManager(), md5(json_encode($composerConfig))); $composer->setLocker($locker); $eventDispatcher = $this->getMockBuilder('Composer\Script\EventDispatcher')->disableOriginalConstructor()->getMock(); $autoloadGenerator = $this->getMock('Composer\Autoload\AutoloadGenerator', array(), array($eventDispatcher)); $composer->setAutoloadGenerator($autoloadGenerator); $composer->setEventDispatcher($eventDispatcher); $installer = Installer::create( $io, $composer ); $application = new Application; $application->get('install')->setCode(function ($input, $output) use ($installer) { $installer->setDevMode($input->getOption('dev')); return $installer->run() ? 0 : 1; }); $application->get('update')->setCode(function ($input, $output) use ($installer) { $installer ->setDevMode($input->getOption('dev')) ->setUpdate(true) ->setUpdateWhitelist($input->getArgument('packages')); return $installer->run() ? 0 : 1; }); if (!preg_match('{^(install|update)\b}', $run)) { throw new \UnexpectedValueException('The run command only supports install and update'); } $application->setAutoExit(false); $appOutput = fopen('php://memory', 'w+'); $result = $application->run(new StringInput($run), new StreamOutput($appOutput)); fseek($appOutput, 0); $this->assertEquals(0, $result, $output . stream_get_contents($appOutput)); if ($expectLock) { unset($actualLock['hash']); unset($actualLock['_readme']); $this->assertEquals($expectLock, $actualLock); } $installationManager = $composer->getInstallationManager(); $this->assertSame($expect, implode("\n", $installationManager->getTrace())); if ($expectOutput) { $this->assertEquals($expectOutput, $output); } }
/** * Resets all Composer references in the application. * * @param ComposerApplication $application */ private function resetComposers(ComposerApplication $application) { $application->resetComposer(); foreach ($this->getApplication()->all() as $command) { if ($command instanceof BaseCommand) { $command->resetComposer(); } } }