PHP编写的SVN类
添加时间:2013-7-17 点击量:
<?php
/
SVN 外部号令 类
@author rubekid
@todo comment need addslashes for svn commit
/
class SvnUtils {
/
svn 账号
/
const SVN_USERNAME = rubekid;
/
svn 暗码
/
const SVN_PASSWORD = 123456;
/
设备文件目次 (随便率性指定一个姑且目次,解决svn: warning: Cant open file /root/.subversion/servers: Permission denied)
/
const SVN_CONFIG_DIR = /var/tmp/;
/
svn list
@param ¥repository string
@return boolean
/
static public function ls(¥repository) {
¥command = svn ls . ¥repository;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, non-existent in that revision )) {
return false;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn copy
@param ¥src string
@param ¥dst string
@param ¥comment string
@return boolean
/
static public function copy(¥src, ¥dst, ¥comment) {
¥command = svn cp ¥src ¥dst -m ¥comment;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, Committed revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn
@param ¥url string
@param ¥comment string
@return boolean
/
static public function (¥url, ¥comment) {
¥command = svn del ¥url -m ¥comment;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, Committed revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn move
@param ¥src string
@param ¥dst string
@param ¥comment string
@return boolean
/
static public function move(¥src, ¥dst, ¥comment) {
¥command = svn mv ¥src ¥dst -m ¥comment;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, Committed revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn mkdir
@param ¥url string
@param ¥comment string
@return boolean
/
static public function mkdir(¥url, ¥comment) {
¥command = svn mkdir ¥url -m ¥comment;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, Committed revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn diff
@param ¥pathA string
@param ¥pathB string
@return string
/
static public function diff(¥pathA, ¥pathB) {
¥output = self::runCmd ( svn diff ¥pathA ¥pathB );
return implode ( <br />, ¥output );
}
/
svn checkout
@param ¥url string
@param ¥dir string
@return boolean
/
static public function checkout(¥url, ¥dir) {
¥command = cd ¥dir && svn co ¥url;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strstr ( ¥output, Checked out revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn
@param ¥path string
/
static public function (¥path) {
¥command = cd ¥path && svn up;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
preg_match_all ( /[0-9]+/, ¥output, ¥ret );
if (! ¥ret [0] [0]) {
return <br /> . ¥command . <br /> . ¥output;
}
return ¥ret [0] [0];
}
/
svn merge
@param ¥revision string
@param ¥url string
@param ¥dir string
@return boolean
/
static public function merge(¥revision, ¥url, ¥dir) {
¥command = cd ¥dir && svn merge -r1:¥revision ¥url;
¥output = implode ( <br />, self::runCmd ( ¥command ) );
if (strstr ( ¥output, Text conflicts )) {
return Command: . ¥command . <br /> . ¥output;
}
return true;
}
/
svn commit
@param ¥dir string
@param ¥comment string
@return boolean
/
static public function commit(¥dir, ¥comment) {
¥command = cd ¥dir && svn commit -m¥comment;
¥output = implode ( <br />, self::runCmd ( ¥command ) );
if (strpos ( ¥output, Committed revision ) || empty ( ¥output )) {
return true;
}
return ¥output;
}
/
svn status (输出WC中文件和目次的状况)
@param ¥dir string
/
static public function getStatus(¥dir) {
¥command = cd ¥dir && svn st;
return self::runCmd ( ¥command );
}
/
svn 冲突
@param ¥dir string
@return boolean
/
static public function hasConflict(¥dir) {
¥output = self::getStatus ( ¥dir );
foreach ( ¥output as ¥line ) {
if ( substr ( trim ( ¥line ), 0, 1 ) == C || (substr ( trim ( ¥line ), 0, 1 ) == !)) {
return true;
}
}
return false;
}
/
svn log
@param ¥path string
@return string
/
static public function getLog(¥path) {
¥command = svn log ¥path --xml;
¥output = self::runCmd ( ¥command );
return implode ( , ¥output );
}
/
svn info
@param ¥path string
/
static public function getPathRevision(¥path) {
¥command = svn info ¥path --xml;
¥output = self::runCmd ( ¥command );
¥string = implode ( , ¥output );
¥xml = new SimpleXMLElement ( ¥string );
foreach ( ¥xml->entry [0]->attributes () as ¥key => ¥value ) {
if ( ¥key == revision ) {
return ¥value;
}
}
}
/
svn up
@param ¥path string
/
static public function getHeadRevision(¥path) {
¥command = cd ¥path && svn up;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
preg_match_all ( /[0-9]+/, ¥output, ¥ret );
if (! ¥ret [0] [0]) {
return <br /> . ¥command . <br /> . ¥output;
}
return ¥ret [0] [0];
}
/
Run a cmd and return result
@param ¥command string
@return array
/
static protected function runCmd(¥command) {
¥authCommand = --username . self::SVN_USERNAME . --password . self::SVN_PASSWORD . --no-auth-cache --non-interactive --config-dir . self::SVN_CONFIG_DIR . .subversion;
exec ( ¥command . ¥authCommand . 2>&1, ¥output );
return ¥output;
}
}
看来 Seven Yang 公布的 php svn操纵类 SvnPeer 后,稍作收拾
我所有的自负皆来自我的自卑,所有的英雄气概都来自于我的软弱。嘴里振振有词是因为心里满是怀疑,深情是因为痛恨自己无情。这世界没有一件事情是虚空而生的,站在光里,背后就会有阴影,这深夜里一片寂静,是因为你还没有听见声音。—— 马良《坦白书》
<?php
/
SVN 外部号令 类
@author rubekid
@todo comment need addslashes for svn commit
/
class SvnUtils {
/
svn 账号
/
const SVN_USERNAME = rubekid;
/
svn 暗码
/
const SVN_PASSWORD = 123456;
/
设备文件目次 (随便率性指定一个姑且目次,解决svn: warning: Cant open file /root/.subversion/servers: Permission denied)
/
const SVN_CONFIG_DIR = /var/tmp/;
/
svn list
@param ¥repository string
@return boolean
/
static public function ls(¥repository) {
¥command = svn ls . ¥repository;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, non-existent in that revision )) {
return false;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn copy
@param ¥src string
@param ¥dst string
@param ¥comment string
@return boolean
/
static public function copy(¥src, ¥dst, ¥comment) {
¥command = svn cp ¥src ¥dst -m ¥comment;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, Committed revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn
@param ¥url string
@param ¥comment string
@return boolean
/
static public function (¥url, ¥comment) {
¥command = svn del ¥url -m ¥comment;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, Committed revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn move
@param ¥src string
@param ¥dst string
@param ¥comment string
@return boolean
/
static public function move(¥src, ¥dst, ¥comment) {
¥command = svn mv ¥src ¥dst -m ¥comment;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, Committed revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn mkdir
@param ¥url string
@param ¥comment string
@return boolean
/
static public function mkdir(¥url, ¥comment) {
¥command = svn mkdir ¥url -m ¥comment;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strpos ( ¥output, Committed revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn diff
@param ¥pathA string
@param ¥pathB string
@return string
/
static public function diff(¥pathA, ¥pathB) {
¥output = self::runCmd ( svn diff ¥pathA ¥pathB );
return implode ( <br />, ¥output );
}
/
svn checkout
@param ¥url string
@param ¥dir string
@return boolean
/
static public function checkout(¥url, ¥dir) {
¥command = cd ¥dir && svn co ¥url;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
if (strstr ( ¥output, Checked out revision )) {
return true;
}
return <br /> . ¥command . <br /> . ¥output;
}
/
svn
@param ¥path string
/
static public function (¥path) {
¥command = cd ¥path && svn up;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
preg_match_all ( /[0-9]+/, ¥output, ¥ret );
if (! ¥ret [0] [0]) {
return <br /> . ¥command . <br /> . ¥output;
}
return ¥ret [0] [0];
}
/
svn merge
@param ¥revision string
@param ¥url string
@param ¥dir string
@return boolean
/
static public function merge(¥revision, ¥url, ¥dir) {
¥command = cd ¥dir && svn merge -r1:¥revision ¥url;
¥output = implode ( <br />, self::runCmd ( ¥command ) );
if (strstr ( ¥output, Text conflicts )) {
return Command: . ¥command . <br /> . ¥output;
}
return true;
}
/
svn commit
@param ¥dir string
@param ¥comment string
@return boolean
/
static public function commit(¥dir, ¥comment) {
¥command = cd ¥dir && svn commit -m¥comment;
¥output = implode ( <br />, self::runCmd ( ¥command ) );
if (strpos ( ¥output, Committed revision ) || empty ( ¥output )) {
return true;
}
return ¥output;
}
/
svn status (输出WC中文件和目次的状况)
@param ¥dir string
/
static public function getStatus(¥dir) {
¥command = cd ¥dir && svn st;
return self::runCmd ( ¥command );
}
/
svn 冲突
@param ¥dir string
@return boolean
/
static public function hasConflict(¥dir) {
¥output = self::getStatus ( ¥dir );
foreach ( ¥output as ¥line ) {
if ( substr ( trim ( ¥line ), 0, 1 ) == C || (substr ( trim ( ¥line ), 0, 1 ) == !)) {
return true;
}
}
return false;
}
/
svn log
@param ¥path string
@return string
/
static public function getLog(¥path) {
¥command = svn log ¥path --xml;
¥output = self::runCmd ( ¥command );
return implode ( , ¥output );
}
/
svn info
@param ¥path string
/
static public function getPathRevision(¥path) {
¥command = svn info ¥path --xml;
¥output = self::runCmd ( ¥command );
¥string = implode ( , ¥output );
¥xml = new SimpleXMLElement ( ¥string );
foreach ( ¥xml->entry [0]->attributes () as ¥key => ¥value ) {
if ( ¥key == revision ) {
return ¥value;
}
}
}
/
svn up
@param ¥path string
/
static public function getHeadRevision(¥path) {
¥command = cd ¥path && svn up;
¥output = self::runCmd ( ¥command );
¥output = implode ( <br />, ¥output );
preg_match_all ( /[0-9]+/, ¥output, ¥ret );
if (! ¥ret [0] [0]) {
return <br /> . ¥command . <br /> . ¥output;
}
return ¥ret [0] [0];
}
/
Run a cmd and return result
@param ¥command string
@return array
/
static protected function runCmd(¥command) {
¥authCommand = --username . self::SVN_USERNAME . --password . self::SVN_PASSWORD . --no-auth-cache --non-interactive --config-dir . self::SVN_CONFIG_DIR . .subversion;
exec ( ¥command . ¥authCommand . 2>&1, ¥output );
return ¥output;
}
}
看来 Seven Yang 公布的 php svn操纵类 SvnPeer 后,稍作收拾