Php operations SVN version server class code _ PHP Tutorial

Source: Internet
Author: User
Php operates the SVN version server code. The code for copying SvnPeer. php code is as follows :? Php *** Thisclassforexecutetheexternalprogramofsvn *** @ authSevenYangqineer@gmail.com *** classSvnPeer {*** Listdirector SvnPeer. php

The code is as follows:


/**
*
* This class for execute the external program of svn
*
* @ Auth Seven Yang
*
*/
Class SvnPeer
{
/**
* List directory entries in the repository
*
* @ Param string a specific project repository path
* @ Return bool true, if validated successfully, otherwise false
*/
Static public function ls ($ repository)
{
$ Command = "svn ls". $ repository;
$ Output = SvnPeer: runCmd ($ command );
$ Output = implode ("
", $ Output );
If (strpos ($ output, 'non-existent in that revision ')){
Return false;
}
Return"
". $ Command ."
". $ Output;
}
/**
* Duplicate something in working copy or repository, remembering history
*
* @ Param $ src
* @ Param $ dst
* @ Param $ comment string specify log message
* @ Return bool true, if copy successfully, otherwise return the error message
*
* @ Todo comment need addslashes for svn commit
*/
Static public function copy ($ src, $ dst, $ comment)
{
$ Command = "svn cp $ src $ dst-M' $ comment '";
$ Output = SvnPeer: runCmd ($ command );
$ Output = implode ("
", $ Output );
If (strpos ($ output, 'committed revision ')){
Return true;
}
Return"
". $ Command ."
". $ Output;
}
/**
* Remove files and directories from version control
*
* @ Param $ url
* @ Return bool true, if delete successfully, otherwise return the error message
*
* @ Todo comment need addslashes for svn commit
*/
Static public function delete ($ url, $ comment)
{
$ Command = "svn del $ url-M' $ comment '";
$ Output = SvnPeer: runCmd ($ command );
$ Output = implode ('
', $ Output );
If (strpos ($ output, 'committed revision ')){
Return true;
}
Return"
". $ Command ."
". $ Output;
}
/**
* Move and/or rename something in working copy or repository
*
* @ Param $ src string trunk path
* @ Param $ dst string new branch path
* @ Param $ comment string specify log message
* @ Return bool true, if move successfully, otherwise return the error message
*
* @ Todo comment need addslashes for svn commit
*/
Static public function move ($ src, $ dst, $ comment)
{
$ Command = "svn mv $ src $ dst-M' $ comment '";
$ Output = SvnPeer: runCmd ($ command );
$ Output = implode ('
', $ Output );
If (strpos ($ output, 'committed revision ')){
Return true;
}
Return"
". $ Command ."
". $ Output;
}
/**
* Create a new directory under version control
*
* @ Param $ url string
* @ Param $ comment string the svn message
* @ Return bool true, if create successfully, otherwise return the error message
*
* @ Todo comment need addslashes for svn commit
*/
Static public function mkdir ($ url, $ comment)
{
$ Command = "svn mkdir $ url-M' $ comment '";
$ Output = SvnPeer: runCmd ($ command );
$ Output = implode ('
', $ Output );
If (strpos ($ output, 'committed revision ')){
Return true;
}
Return"
". $ Command ."
". $ Output;
}
Static public function diff ($ pathA, $ pathB)
{
$ Output = SvnPeer: runCmd ("svn diff $ pathA $ pathB ");
Return implode ('
', $ Output );
}
Static public function checkout ($ url, $ dir)
{
$ Command = "cd $ dir & svn co $ url ";
$ Output = SvnPeer: runCmd ($ command );
$ Output = implode ('
', $ Output );
If (strstr ($ output, 'checked out revision ')){
Return true;
}
Return"
". $ Command ."
". $ Output;
}
Static public function update ($ path)
{
$ Command = "cd $ path & svn up ";
$ Output = SvnPeer: runCmd ($ command );
$ Output = implode ('
', $ Output );
Preg_match_all ("/[0-9] +/", $ output, $ ret );
If (! $ Ret [0] [0]) {
Return"
". $ Command ."
". $ Output;
}
Return $ ret [0] [0];
}
Static public function merge ($ revision, $ url, $ dir)
{
$ Command = "cd $ dir & svn merge-r1: $ revision $ url ";
$ Output = implode ('
', SvnPeer: runCmd ($ command ));
If (strstr ($ output, 'text conflicts ')){
Return 'command: '. $ Command .'
'. $ Output;
}
Return true;
}
Static public function commit ($ dir, $ comment)
{
$ Command = "cd $ dir & svn commit-M' $ comment '";
$ Output = implode ('
', SvnPeer: runCmd ($ command ));
If (strpos ($ output, 'committed revision') | empty ($ output )){
Return true;
}
Return $ output;
}
Static public function getStatus ($ dir)
{
$ Command = "cd $ dir & svn st ";
Return SvnPeer: runCmd ($ command );
}
Static public function hasConflict ($ dir)
{
$ Output = SvnPeer: getStatus ($ dir );
Foreach ($ output as $ line ){
If ('C' = substr (trim ($ line), 0, 1) | ('! '= Substr (trim ($ line), 0, 1 ))){
Return true;
}
}
Return false;
}
/**
* Show the log messages for a set of path with XML
*
* @ Param path string
* @ Return log message string
*/
Static public function getLog ($ path)
{
$ Command = "svn log $ path -- xml ";
$ Output = SvnPeer: runCmd ($ command );
Return implode ('', $ output );
}
Static public function getPathRevision ($ path)
{
$ Command = "svn info $ path -- xml ";
$ Output = SvnPeer: runCmd ($ command );
$ String = implode ('', $ output );
$ Xml = new SimpleXMLElement ($ string );
Foreach ($ xml-> entry [0]-> attributes () as $ key => $ value ){
If ('review' = $ key ){
Return $ value;
}
}
}
Static public function getHeadRevision ($ path)
{
$ Command = "cd $ path & svn up ";
$ Output = SvnPeer: runCmd ($ command );
$ Output = implode ('
', $ Output );
Preg_match_all ("/[0-9] +/", $ output, $ ret );
If (! $ Ret [0] [0]) {
Return"
". $ Command ."
". $ Output;
}
Return $ ret [0] [0];
}
/**
* Run a cmd and return result
*
* @ Param string command line
* @ Param boolen true need add the svn authentication
* @ Return array the contents of the output that svn execute
*/
Static protected function runCmd ($ command)
{
$ AuthCommand = '-- username '. SVN_USERNAME. '-- password '. SVN_PASSWORD. '-- no-auth-cache -- non-interactive -- config-dir '. SVN_CONFIG_DIR. '. subversion ';
Exec ($ command. $ authCommand. "2> & 1", $ output );
Return $ output;
}
}

The http://www.bkjia.com/PHPjc/324524.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324524.htmlTechArticleSvnPeer.php code is as follows :? Php/*** This class for execute the external program of svn *** @ auth Seven Yang qineer@gmail.com **/class SvnPeer {/*** List director...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.