git::config PHP Method

config() static public method

# -----------------------------------------------------------------------------------------------
static public config ( $key = null, $value = null, $guess_repo = true )
    static function config($key = null, $value = null, $guess_repo = true)
    {
        if ($value !== null) {
            $cmd = 'config --replace-all ';
            if ($value === true || $value === false) {
                $cmd .= ' --bool ';
                $value = $value ? 'true' : 'false';
            } elseif (is_int($value)) {
                $cmd .= ' --int ';
            }
            return trim(self::exec($cmd . escapeshellarg($key) . ' ' . escapeshellarg($value), null, null, null, $guess_repo));
        } else {
            try {
                return trim(self::exec('config --get ' . escapeshellarg($key), null, null, null, $guess_repo));
            } catch (GitError $e) {
                if (trim($e->getMessage()) === '') {
                    return null;
                }
                throw $e;
            }
        }
    }

Usage Example

Example #1
0
# prepare for rendering
gb::$title[] = 'Setup';
$is_writable = is_writable(gb::$site_dir);
if (!$is_writable) {
    gb::$errors[] = '<b>Ooops.</b> The directory <code>' . h(gb::$site_dir) . '</code> is not writable.
		Gitblog need to create a few files in this directory.
		<br/><br/>
		Please make this directory (highlighted above) writable and then reload this page.';
    # todo: check if the web server user and/or is the same as user and/or group
    #       on directory. If so, suggest a chmod, otherwise suggest a chown.
}
if (!isset($_POST['email'])) {
    $_POST['email'] = git::config('user.email');
}
if (!isset($_POST['name'])) {
    $_POST['name'] = git::config('user.name');
}
include '_header.php';
?>
<script type="text/javascript" charset="utf-8">
	$(function(){
		$('input[name=email]').focus();
	});
</script>
<div id="content" class="setup margins">
	<h2>Setup your gitblog</h2>
	<p>
		It's time to setup your new gitblog.
	</p>
	<form action="setup.php" method="post">