public static function guessCurrentBranchName()

in lib/php/libsdk/SDK/Config.php [187:243]


	public static function guessCurrentBranchName() : ?string
	{/*{{{*/
		$branch = NULL;
		$found = false;

		$rmtools_branch = getenv("PHP_RMTOOLS_PHP_BUILD_BRANCH");
		if ("master" == $rmtools_branch) {
			return "master";
		}

		/* Try to figure out the branch. The worky scenarios are
			- CWD is in php-src 
			- phpize is on the path
			FIXME for the dev package, there should be a php-config utility
		 */
		$fl = "main/php_version.h";
		$found = file_exists($fl);

		if (!$found) {
			exec("where phpize", $out, $status);
			if (!$status) {
				$fl = dirname($out[0]) . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . $fl;
				$found = file_exists($fl);
			}
		}

		if ($found) {
			$s = file_get_contents($fl);
			$major = $minor = NULL;

			if (preg_match(",PHP_MAJOR_VERSION (\d+),", $s, $m)) {
				$major = $m[1];
			}
			if (preg_match(",PHP_MINOR_VERSION (\d+),", $s, $m)) {
				$minor = $m[1];
			}

			if (is_numeric($major) && is_numeric($minor)) {
				$branch = "$major.$minor";
			}

			/* Verify that we use an available branch name. Master has some
				version, but no dedicated series. For master, it rather
				makes sense to use master as branch name. */
			$git = trim(shell_exec("where git.exe"));
			if ($git && is_dir(".git")) {
				$cmd = "\"$git\" branch";

				$ret = trim(shell_exec($cmd));
				if (preg_match_all(",\*\s+master,", $ret) > 0) {	
					$branch = "master";
				}
			}
		}

		return $branch;
	}/*}}}*/