/** * Initialize controller */ public function Initialize() { $this->InitializeConfig(); $this->InitializeUserList(); $this->InitializeGitExe(); $this->InitializeProjectList(); // HACK: this needs to be done early because the snapshot controller modifies the headers before opening the archive if (!GitPHP_Util::FunctionAllowed('popen')) { throw new GitPHP_DisabledFunctionException('popen'); } if (isset($this->params['project'])) { $project = $this->projectList->GetProject($this->params['project']); if (!$project) { throw new GitPHP_InvalidProjectParameterException($this->params['project']); } if ($this->userList && $this->userList->GetCount() > 0) { if (!$project->UserCanAccess(!empty($_SESSION['gitphpuser']) ? $_SESSION['gitphpuser'] : null)) { throw new GitPHP_UnauthorizedProjectException($this->params['project']); } } $this->project = $project->GetProject(); } if (!$this->project) { throw new GitPHP_MissingProjectParameterException(); } $this->preserveWhitespace = true; if (empty($this->params['format'])) { $this->params['format'] = $this->config->GetValue('compressformat'); } $this->InitializeArchive(); if ($this->config->GetValue('cache')) { $this->cacheDir = GITPHP_CACHEDIR . 'snapshots/'; if (file_exists($this->cacheDir)) { if (!is_dir($this->cacheDir)) { throw new Exception($this->cacheDir . ' exists but is not a directory'); } else { if (!is_writable($this->cacheDir)) { throw new Exception($this->cacheDir . ' is not writable'); } } } else { if (!mkdir($this->cacheDir, 0777)) { throw new Exception($this->cacheDir . ' could not be created'); } chmod($this->cacheDir, 0777); } } }
/** * Tests if this executable is valid * * @return boolean true if valid */ public function Valid() { if ($this->execAllowed === null) { $this->execAllowed = GitPHP_Util::FunctionAllowed('exec'); if (!$this->execAllowed) { throw new GitPHP_DisabledFunctionException('exec'); } } if (empty($this->binary)) { return false; } $code = 0; exec($this->binary . ' --version', $tmp, $code); return $code == 0; }