Created
June 21, 2013 22:44
-
-
Save Danack/5834881 to your computer and use it in GitHub Desktop.
Composer Runner - calls composer update from a PHP script. Not recommended practice at all but may be necessary for people using web servers where they don't have shell access.
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 | |
// | |
//Yes you can run Composer with a little PHP wrapper. All of the Composer source code is available in the Phar file, so it can be extracted and then you can run it after setting up an InputInterface to replace Composer expecting the commands to be passed in via the command line. | |
// | |
//If you setup your directory structure like this: | |
// | |
//./project | |
//./project/composer.json | |
//./project/composer.lock | |
//./project/webroot/composerExtractor.php | |
//./project/var/ | |
//Put the code below into composerExtractor.php and then run it from a web-browser, Composer should download all the libraries into: | |
//./project/vendors/ | |
//As well as generating the class-loader files in that directory as well. | |
define('EXTRACT_DIRECTORY', "../var/extractedComposer"); | |
if (file_exists(EXTRACT_DIRECTORY.'/vendor/autoload.php') == true) { | |
echo "Extracted autoload already exists. Skipping phar extraction as presumably it's already extracted."; | |
} | |
else{ | |
$composerPhar = new Phar("Composer.phar"); | |
//php.ini setting phar.readonly must be set to 0 | |
$composerPhar->extractTo(EXTRACT_DIRECTORY); | |
} | |
//This requires the phar to have been extracted successfully. | |
require_once (EXTRACT_DIRECTORY.'/vendor/autoload.php'); | |
//Use the Composer classes | |
use Composer\Console\Application; | |
use Composer\Command\UpdateCommand; | |
use Symfony\Component\Console\Input\ArrayInput; | |
// change out of the webroot so that the vendors file is not created in | |
// a place that will be visible to the intahwebz | |
chdir('../'); | |
//Create the commands | |
$input = new ArrayInput(array('command' => 'update')); | |
//Create the application and run it with the commands | |
$application = new Application(); | |
$application->run($input); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment