Created
October 2, 2016 19:35
-
-
Save ahsankhatri/556064662d368d63ad51483cecc7eb27 to your computer and use it in GitHub Desktop.
Run composer update/install in browser.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This is just a sample code, do not use it on production as this is insecure | |
// For security, you may use .htaccess IP Access or HTTP Basic Aauthentication | |
require 'vendor/autoload.php'; | |
$allowedCommands = [ | |
'update', | |
'install', | |
'dump-autoload', | |
'dump-autoload -o', | |
]; | |
showOptions($allowedCommands); | |
if ( !isset($_GET['cmd']) ) { | |
exit('<br />'); | |
} | |
$cmdRaw = base64_decode($_GET['cmd']); | |
if ( !in_array($cmdRaw, $allowedCommands) ) { | |
exit; | |
} | |
$cmdRawArray = explode(' ', $cmdRaw); | |
$inputArray = ['command' => array_shift($cmdRawArray) ] + $cmdRawArray; | |
ini_set('memory_limit', '1G'); | |
set_time_limit(300); // 5 minutes execution | |
use Composer\Console\Application; | |
use Symfony\Component\Console\Input\ArrayInput; | |
use Symfony\Component\Console\Output\BufferedOutput as Output; | |
use Symfony\Component\Console\Output\OutputInterface; | |
$isDebug = isset($_GET['debug']) ? true : false; | |
// set COMPOSER_HOME environment | |
putenv('COMPOSER_HOME=' . __DIR__ . '/vendor/bin/composer'); | |
$output = new Output( | |
$isDebug ? OutputInterface::VERBOSITY_DEBUG : OutputInterface::VERBOSITY_NORMAL | |
); | |
$input = new ArrayInput( $inputArray ); | |
$application = new Application(); | |
$application->setAutoExit(false); | |
$application->run($input, $output); | |
echo '<pre>' . $output->fetch() . '</pre>'; | |
function showOptions($allowedCommands) { | |
$buttons = []; | |
foreach ($allowedCommands as $cmd) { | |
$buttons[] = '<button type="button" onclick="window.location=\'' . $_SERVER['SCRIPT_NAME'] . '?cmd=' . base64_encode($cmd) . '\'">composer ' . $cmd . '</button>'; | |
} | |
echo implode(' ', $buttons) . '<hr>'; | |
} |
not works with 'require vendor/PackageName'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you @ahsankhatri, this code of yours is a big help to me.
Can you make the output is showing on install progress? not after it..
It really help.