<?php
error_reporting(E_ALL);
require 'AnmpServer.inc.php';

$SERVER_TYPE = trim($_SERVER['argv'][1]);
var_dump( $_SERVER['argv']);


// 切换MySQL版本
if ('MySQL' === $SERVER_TYPE) {
	anmp_log("EXEC SWITCH [{$_SERVER['argv'][2]} {$_SERVER['argv'][3]}");
	anmp_set_ini(array('mysql_vers' => trim($_SERVER['argv'][3])));
}


// 切换Apache版本
if ('Apache' === $SERVER_TYPE) {
	anmp_log("EXEC SWITCH [{$_SERVER['argv'][2]} {$_SERVER['argv'][3]}");
	anmp_set_ini(array(
		'apache_vers' => trim($_SERVER['argv'][3]),
		'apache_verh' => trim($_SERVER['argv'][4]),
		'apache_verp' => trim($_SERVER['argv'][5]),
	));

	$httpd_conf_phpmod = ANMP_ROOT . '/conf/httpd/httpd-mod_php.conf';
	$content = file_get_contents($httpd_conf_phpmod);

	$find_phpv = '#php-([\d\.]+)-win(\d{2})#u';
	$repl_phpv = trim($_SERVER['argv'][5]);

	$content = preg_replace($find_phpv, $repl_phpv, $content);
	file_put_contents($httpd_conf_phpmod, $content);
}


echo "\nPress Enter to exit...";
// trim(fgets(STDIN));
exit(0);