1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | <?php /** * GitPHP GitExe * * Class to wrap git executable * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2010 Christopher Han * @package GitPHP * @subpackage Git */ /** * Git Executable class * * @package GitPHP * @subpackage Git */ class GitPHP_GitExe { /** * project * * Stores the project internally * * @access protected */ protected $project; /** * bin * * Stores the binary path internally * * @access protected */ protected $binary; /** * __construct * * Constructor * * @param string $binary path to git binary * @param mixed $project project to operate on * @return mixed git executable class */ public function __construct($project = null) { $this->binary = GitPHP_Config::GetInstance()->GetValue('gitbin'); if (empty($binary)) { // try to pick a reasonable default if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $this->binary = 'C:\\Progra~1\\Git\\bin\\git.exe'; } else { $this->binary = 'git'; } } else { $this->binary = $binary; } $this->SetProject($project); } /** * SetProject * * Sets the project for this executable * * @param mixed $project project to set */ public function SetProject($project = null) { $this->project = $project; } /** * Execute * * Executes a command * * @param string $command the command to execute * @param array $args arguments * @return string result of command */ public function Execute($command, $args) { $gitDir = ''; if ($this->project) { $gitDir = '--git-dir=' . $this->project->GetPath(); } $fullCommand = $this->binary . ' ' . $gitDir . ' ' . $command . ' ' . implode(' ', $args); return shell_exec($fullCommand); } /** * GetBinary * * Gets the binary for this executable * * @return string $param * @access public */ public function GetBinary() { return $this->binary; } } |