Created
November 29, 2013 14:32
-
-
Save rechl/7706500 to your computer and use it in GitHub Desktop.
How i would like to use Composer Install Commands with CloudControl
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 | |
namespace APPNAME\Composer; | |
use Composer\Script\Event; | |
class Install | |
{ | |
private static $appName = 'APPNAME'; | |
private static $depoymentName = 'DEPLOYMENTNAME'; | |
private static $newrelicApiKey = 'ENTER YOUR NEW RELIC API KEY'; | |
private static $cloudcontrolUser = 'ENTER YOUR cloudcontrol Username'; | |
public static function preInstall(Event $event) { | |
// provides access to the current ComposerIOConsoleIO | |
// stream for terminal input/output | |
$io = $event->getIO(); | |
$io->write("Installing ".self::$appname); | |
$io->write("Deployment ".self::$depoymentName); | |
} | |
public static function preUpdate(Event $event) { | |
// provides access to the current ComposerIOConsoleIO | |
// stream for terminal input/output | |
$io = $event->getIO(); | |
$io->write("Updating ".self::$appname); | |
$io->write("Deployment ".self::$depoymentName); | |
} | |
public static function postInstall(Event $event) { | |
// provides access to the current Composer instance | |
$composer = $event->getComposer(); | |
// run any post install tasks here | |
$io = $event->getIO(); | |
if ( $_SERVER['PAAS_VENDOR'] == 'cloudControl' ) { | |
$ch = curl_init(); | |
if ($event->isDevMode()){ | |
$deployment = "dev"; | |
}else { | |
$deployment = "default"; | |
} | |
$description = "Automatic deployment info"; | |
$data ="deployment[app_name]=".self::$appName.'/'.self::$depoymentName. | |
"&deployment[description]=".$description. | |
"&deployment[user]=".self::$cloudcontrolUser; | |
curl_setopt($ch, CURLOPT_URL, 'https://rpm.newrelic.com/deployments.xml'); | |
curl_setopt($ch,CURLOPT_HTTPHEADER,array('x-api-key:'.self::$newrelicApiKey)); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_POST ,1); | |
curl_exec($ch); | |
curl_close($ch); | |
} | |
$io->write("Installed ".self::$appName); | |
} | |
public static function postPackageInstall(Event $event) { | |
$installedPackage = $event->getComposer()->getPackage(); | |
// any tasks to run after the package is installed? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And the sample composer.json can be found here
https://gist.github.com/sgotre/7706650