#! /usr/bin/env php
<?php
/**
 * This is an EXAMPLE script for invoking the git hook controller
 * Although fully functional for standalone bart installations, if
 * bart is composed in your project, you may want to configure your
 * app via your own PHP boot strap code prior to invoking the controller
 *
 * Expected system configuration of hooks is that there is a directory of git hook
 * and one of them is a symlink to this bart script. E.g.:
 *
 *     /path/to/repos/repo.git/hooks/post-receive.d/hook-name -> /path/to/bart/bin/git-hook-runner.php
 *
 * Necessary runtime configuration for Hooks:
 *    BART/etc/php/hooks.conf
 * 		- (this is the old school configuration, which is deprecated but not yet replaced; sorry)
 *    Configuration Root/*.conf
 * 		- Configuration for any of the GitHook classes. Presently, this includes only GerritMerged
 */
use Bart\GitHook\GitHookController;
use Bart\Log4PHP;

error_reporting(E_ALL);

$bartRoot = dirname(__DIR__);
require_once "$bartRoot/src/Bart/bart-common.php";
require_once "$bartRoot/vendor/autoload.php";

Log4PHP::initForConsole('trace');
$logger = \Logger::getLogger(__CLASS__);

// Hook up root of where to find system wide app configuration files
// Your system configuration or deployment tools should be responsible for
// ...defining the content of the files in this directory
// NOTE *project* configuration files belong checked into repo in the 'etc' dir
\Bart\Configuration\Configuration::configure('/box/etc');

$controller = GitHookController::createFromScriptName($_SERVER['SCRIPT_NAME']);
$logger->debug("Created git hook controller $controller");


try {
	$controller->run();
}
catch (\Exception $e) {
	echo \Bart\EscapeColors::red("

		$controller failed: {$e->getMessage()}

");
	exit(1);
}
