Skip to content

Instantly share code, notes, and snippets.

@sgotre
Created November 29, 2013 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgotre/7706500 to your computer and use it in GitHub Desktop.
Save sgotre/7706500 to your computer and use it in GitHub Desktop.
How i would like to use Composer Install Commands with CloudControl
<?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?
}
}
@sgotre
Copy link
Author

sgotre commented Nov 29, 2013

And the sample composer.json can be found here

https://gist.github.com/sgotre/7706650

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment