• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php操作SVN版本服务器类代码_php技巧

php 搞代码 4年前 (2022-01-26) 14次浏览 已收录 0个评论

SvnPeer.php

 <BR><?php <BR>/** <BR>* <BR>* This class for execute the external program of svn <BR>* <BR>* @auth Seven Yang  <BR>* <BR>*/ <BR>class SvnPeer <BR>{ <BR>/** <BR>* List directory entries in the repository <BR>* <BR>* @param string a specific project repository path <BR>* @return bool true, if validated successfully, otherwise false <BR>*/ <BR>static public function ls($repository) <BR>{ <BR>$command = "svn ls " . $repository; <BR>$output = SvnPeer::runCmd($command); <BR>$output = implode("<br>", $output); <BR>if (strpos($output, 'non-existent in that revision')) { <BR>return false; <BR>} <BR>return "<br>" . $command . "<br>" . $output; <BR>} <BR>/** <BR>* Duplicate something in working copy or repository, remembering history <BR>* <BR>* @param $src <BR>* @param $dst <BR>* @param $comment string specify log message <BR>* @return bool true, if copy successfully, otherwise return the error message <BR>* <BR>* @todo comment need addslashes for svn commit <BR>*/ <BR>static public function copy($src, $dst, $comment) <BR>{ <BR>$command = "svn cp $src $dst -m '$comment'"; <BR>$output = SvnPeer::runCmd($command); <BR>$output = implode("<br>", $output); <BR>if (strpos($output, 'Committed revision')) { <BR>return true; <BR>} <BR>return "<br>" . $command . "<br>" . $output; <BR>} <BR>/** <BR>* Remove files and directories from version control <BR>* <BR>* @param $url <BR>* @return bool true, if delete successfully, otherwise return the error message <BR>* <BR>* @todo comment need addslashes for svn commit <BR>*/ <BR>static public function delete($url, $comment) <BR>{ <BR>$command = "svn del $url -m '$comment'"; <BR>$output = SvnPeer::runCmd($command); <BR>$output = implode('<br>', $output); <BR>if (strpos($output, 'Committed revision')) { <BR>return true; <BR>} <BR>return "<br>" . $command . "<br>" . $output; <BR>} <BR>/** <BR>* Move and/or rename something in working copy or repository <BR>* <BR>* @param $src string trunk path <BR>* @param $dst string new branch path <BR>* @param $comment string specify log message <BR>* @return bool true, if move successfully, otherwise return the error message <BR>* <BR>* @todo comment need addslashes for svn commit <BR>*/ <BR>static public function move($src, $dst, $comment) <BR>{ <BR>$command = "svn mv $src $dst -m '$comment'"; <BR>$output = SvnPeer::runCmd($command); <BR>$output = implode('<br>', $output); <BR>if (strpos($output, 'Committed revision')) { <BR>return true; <BR>} <BR>return "<br>" . $command . "<br>" . $output; <BR>} <BR>/** <BR>* Create a new directory under version control <BR>* <BR>* @param $url string <BR>* @param $comment string the svn message <BR>* @return bool true, if create successfully, otherwise return the error message <BR>* <BR>* @todo comment need addslashes for svn commit <BR>*/ <BR>static public function mkdir($url, $comment) <BR>{ <BR>$command = "svn mkdir $url -m '$comment'"; <BR>$output = SvnPeer::runCmd($command); <BR>$output = implode('<br>', $output); <BR>if (strpos($output, 'Committed revision')) { <BR>return true; <BR>} <BR>return "<br>" . $command . "<br>" . $output; <BR>} <BR>static public function diff($pathA, $pathB) <BR>{ <BR>$output = SvnPeer::runCmd("svn diff $pathA $pathB"); <BR>return implode('<br>', $output); <BR>} <BR>static public function checkout($url, $dir) <BR>{ <BR>$command = "cd $dir && svn co $url"; <BR>$output = SvnPeer::runCmd($command); <BR>$output = implode('<br>', $output); <BR>if (strstr($output, 'Checked out revision')) { <BR>return true; <BR>} <BR>return "<br>" . $command . "<br>" . $output; <BR>} <BR>static public function update($path) <BR>{ <BR>$command = "cd $path && svn up"; <BR>$output = SvnPeer::runCmd($command); <BR>$output = implode('<br>', $output); <BR>preg_match_all("/[0-9]+/", $output, $ret); <BR>if (!$ret[0][0]){ <BR>return "<br>" . $command . "<br>" . $output; <BR>} <BR>return $ret[0][0]; <BR>} <BR>static public function merge($revision, $url, $dir) <BR>{ <BR>$command = "cd $dir && svn merge -r1:$revision $url"; <BR>$output = implode('<br>', SvnPeer::runCmd($command)); <BR>if (strstr($output, 'Text conflicts')) { <BR>return 'Command: ' . $command .'<br>'. $output; <BR>} <BR>return true; <BR>} <BR>static public function commit($dir, $comment) <BR>{ <BR>$command = "cd $dir && svn commit -m'$comment'"; <BR>$output = implode('<br>', SvnPeer::runCmd($command)); <BR>if (strpos($output, 'Committed revision') || empty($output)) { <BR>return true; <BR>} <BR>return $output; <BR>} <BR>static public function getStatus($dir) <BR>{ <BR>$command = "cd $dir && svn st"; <BR>return SvnPeer::runCmd($command); <BR>} <BR>static public function hasConflict($dir) <BR>{ <BR>$output = SvnPeer::getStatus($dir); <BR>foreach ($output as $line){ <BR>if ('C' == substr(trim($line), 0, 1) || ('!' == substr(trim($line), 0, 1))){ <BR>return true; <BR>} <BR>} <BR>return false; <BR>} <BR>/** <BR>* Show the log messages for a set of path with XML <BR>* <BR>* @param path string <BR>* @return log message string <BR>*/ <BR>static public function getLog($path) <BR>{ <BR>$command = "svn log $path --xml"; <BR>$output = SvnPeer::runCmd($command); <BR>return implode('', $output); <BR>} <BR>static public function getPathRevision($path) <BR>{ <BR>$command = "svn info $path --xml"; <BR>$output = SvnPeer::runCmd($command); <BR>$string = implode('', $output); <BR>$xml = new SimpleXMLElement($string); <BR>foreach ($xml->entry[0]->attributes() as $key=>$value){ <BR>if ('revision' == $key) { <BR>return $value; <BR>} <BR>} <BR>} <BR>static public function getHeadRevision($path) <BR>{ <BR>$command = "cd $path && svn up"; <BR>$output = SvnPeer::runCmd($command); <BR>$output = implode('<br>', $out<a>本2文来*源gao($daima.com搞@代@#码(网</a><strong>搞gaodaima代码</strong>put); <BR>preg_match_all("/[0-9]+/", $output, $ret); <BR>if (!$ret[0][0]){ <BR>return "<br>" . $command . "<br>" . $output; <BR>} <BR>return $ret[0][0]; <BR>} <BR>/** <BR>* Run a cmd and return result <BR>* <BR>* @param string command line <BR>* @param boolen true need add the svn authentication <BR>* @return array the contents of the output that svn execute <BR>*/ <BR>static protected function runCmd($command) <BR>{ <BR>$authCommand = ' --username ' . SVN_USERNAME . ' --password ' . SVN_PASSWORD . ' --no-auth-cache --non-interactive --config-dir '.SVN_CONFIG_DIR.'.subversion'; <BR>exec($command . $authCommand . " 2>&1", $output); <BR>return $output; <BR>} <BR>} <BR>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php操作SVN版本服务器类代码_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址