Пример #1
0
 /**
  * LoadConfig
  *
  * Loads the config data
  *
  * @access private
  */
 private function LoadConfig()
 {
     $this->configRead = true;
     $path = $this->project->GetPath() . '/config';
     if (!file_exists($path)) {
         return;
     }
     $data = explode("\n", file_get_contents($path));
     $currentSection = '';
     $currentSetting = '';
     foreach ($data as $line) {
         $trimmed = trim($line);
         if (empty($trimmed)) {
             continue;
         }
         if (preg_match('/^\\[(.+)\\]$/', $trimmed, $regs)) {
             // section
             $currentSection = '';
             $currentSetting = '';
             $trimmedSection = trim($regs[1]);
             if (preg_match('/^([0-9A-Za-z\\.\\-]+)( "(.+)")?$/', $trimmedSection, $subRegs)) {
                 $currentSection = strtolower($subRegs[1]);
                 if (!empty($subRegs[3])) {
                     // subsection
                     $currentSection .= '.' . $subRegs[3];
                 }
             }
         } else {
             if (!empty($currentSection)) {
                 // variable
                 $currentSetting .= $trimmed;
                 if (substr($trimmed, -1) === '\\') {
                     // continued on next line
                     continue;
                 }
                 $key = '';
                 $value = null;
                 $eq = strpos($currentSetting, '=');
                 if ($eq !== false) {
                     // key value pair
                     $key = GitPHP_GitConfig::Unescape(trim(substr($currentSetting, 0, $eq)));
                     $value = GitPHP_GitConfig::Unescape(trim(substr($currentSetting, $eq + 1)));
                 } else {
                     // no equals is assumed true
                     $key = GitPHP_GitConfig::Unescape($currentSetting);
                     $value = "true";
                 }
                 if (!empty($key)) {
                     $fullSetting = $currentSection . '.' . strtolower($key);
                     $this->config[$fullSetting][] = $value;
                 }
                 $currentSetting = '';
             }
         }
     }
 }
Пример #2
0
 /**
  * Reads the project's git config settings and applies them to the project
  *
  * @param GitPHP_Project $project project
  */
 protected function ApplyGitConfig($project)
 {
     if (!$project) {
         return;
     }
     $config = null;
     try {
         $config = new GitPHP_GitConfig($project->GetPath() . '/config');
     } catch (Exception $e) {
         return;
     }
     if ($config->HasValue('gitphp.owner')) {
         $project->SetOwner($config->GetValue('gitphp.owner'));
     } else {
         if ($config->HasValue('gitweb.owner')) {
             $project->SetOwner($config->GetValue('gitweb.owner'));
         }
     }
     if ($config->HasValue('gitphp.description')) {
         $project->SetDescription($config->GetValue('gitphp.description'));
     } else {
         if ($config->HasValue('gitweb.description')) {
             $project->SetDescription($config->GetValue('gitweb.description'));
         }
     }
     if ($config->HasValue('gitphp.category')) {
         $project->SetCategory($config->GetValue('gitphp.category'));
     }
     if ($config->HasValue('gitphp.cloneurl')) {
         $project->SetCloneUrl($config->GetValue('gitphp.cloneurl'));
     }
     if ($config->HasValue('gitphp.pushurl')) {
         $project->SetPushUrl($config->GetValue('gitphp.pushurl'));
     }
     if ($config->HasValue('gitphp.bugurl')) {
         $project->SetBugUrl($config->GetValue('gitphp.bugurl'));
     }
     if ($config->HasValue('gitphp.bugpattern')) {
         $project->SetBugPattern($config->GetValue('gitphp.bugpattern'));
     }
     if ($config->HasValue('gitphp.website')) {
         $project->SetWebsite($config->GetValue('gitphp.website'));
     }
     if ($config->HasValue('gitphp.compat')) {
         $project->SetCompat($config->GetValue('gitphp.compat'));
     }
     if ($config->HasValue('core.abbrev')) {
         $project->SetAbbreviateLength($config->GetValue('core.abbrev'));
     }
     if ($config->HasValue('gitphp.allowedusers')) {
         $project->SetAllowedUsers($config->GetValue('gitphp.allowedusers', true));
     }
 }