Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Last active December 16, 2020 22:24
Show Gist options
  • Save IgorDePaula/643ba5985a8defdb17f9 to your computer and use it in GitHub Desktop.
Save IgorDePaula/643ba5985a8defdb17f9 to your computer and use it in GitHub Desktop.
Codigo que atualizar o composer.json e instala o novo compoente atraves de uma pagina em php
<?php
// componentes requeridos
// composer/composer
// symfony/console
// classes requeridas
// use Composer\Command\UpdateCommand;
// use Symfony\Component\Console\Input\ArrayInput;
// use Composer\Console\Application;
//roda o composer para baixar e instalar a dependencia. Antes add-la ao composer.json
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$application = new Application();
$input = new ArrayInput(array(
'command' => 'update'
));
$application->setAutoExit(false);
$application->run($input,$output);
//atualiza o composer para add o componente requerido
$filename = realpath(__DIR__.'/../../../../../').'/composer.json';
$jsonfile = file_get_contents($filename);
echo '<pre>';
$file = json_decode($jsonfile);
$arr = new \ArrayObject($file->require);
$ar = $arr->getArrayCopy();
$ar["monolog/monolog"] = "~1.11";
$file->require = $ar;
file_put_contents($filename, str_replace('\\','',json_encode($file)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment