最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用PHP編寫的SVN類

 更新時間:2013年07月18日 11:13:24   作者:  
以下是使用PHP編寫的一個SVN類。需要的朋友可以參考下

復制代碼 代碼如下:

<?php
/**
 * SVN 外部命令 類
 *
 * @author rubekid
 *
 * @todo comment need addslashes for svn commit
 *
 */
class SvnUtils {
    /**
     *
     * svn 賬號
     */
    const SVN_USERNAME = "robot";
    /**
     * svn 密碼
     */
    const SVN_PASSWORD = "robot2013";
    /**
     * 配置文件目錄   (任意指定一個臨時目錄,解決svn: warning: Can't open file '/root/.subversion/servers': Permission denied)
     */
    const SVN_CONFIG_DIR = "/var/tmp/";

    /**
     * svn list
     *
     * @param $repository string
     * @return boolean
     *
     */
    public static function ls($repository) {
        $command = "sudo 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
     *
     */
    public static function copy($src, $dst, $comment) {
        $command = "sudo 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 delete
     *
     * @param $url string
     * @param $comment string
     * @return boolean
     *
     */
    public static function delete($url, $comment) {
        $command = "sudo 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
     */
    public static function move($src, $dst, $comment) {
        $command = "sudo 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
     */
    public static function mkdir($url, $comment) {
        $command = "sudo 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
     */
    public static function diff($pathA, $pathB) {
        $output = self::runCmd ( "sudo svn diff $pathA $pathB" );
        return implode ( '<br />', $output );
    }
    /**
     * svn checkout
     * @param $url string
     * @param $dir string
     * @return boolean
     */
    public static function checkout($url, $dir) {
        $command = "cd $dir && sudo 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 update
     * @param $path string
     */
    public static function update($path) {
        $command = "cd $path && sudo 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
     */
    public static function merge($revision, $url, $dir) {
        $command = "cd $dir && sudo 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
     */
    public static function commit($dir, $comment) {
        $command = "cd $dir && sudo svn commit -m'$comment'";
        $output = implode ( '<br />', self::runCmd ( $command ) );
        if (strpos ( $output, 'Committed revision' ) || empty ( $output )) {
            return true;
        }
        return $output;
    }
    /**
     * svn status (輸出WC中文件和目錄的狀態(tài))
     *
     * @param $dir string
     */
    public static function getStatus($dir) {
        $command = "cd $dir && sudo svn st";
        return self::runCmd ( $command );
    }
    /**
     * svn 沖突
     *
     * @param $dir string
     * @return boolean
     */
    public static 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
     *
     */
    public static function getLog($path) {
        $command = "sudo svn log $path --xml";
        $output = self::runCmd ( $command );
        return implode ( '', $output );
    }
    /**
     * svn info
     * @param $path string
     */
    public static function getPathRevision($path) {
        $command = "sudo 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;
            }
        }
    }
    /**
     * 獲取最新版本號
     * @param $path string
     */
    public static function getHeadRevision($path) {
        $command = "cd $path && sudo 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];
    }
    /**
     * 獲取某文件最早版本號
     *
     * @param $filePath string
     *
     */
    public static function getFileFirstVersion($filePath){
        $command = "sudo svn log {$filePath}";
        $output = self::runCmd ( $command , "|grep -i ^r[0-9]* |awk  '{print $1}'");
        if(empty($output)){
            return false;
        }
        return str_replace("r", '', $output[count($output)-1]);
    }
    /**
     * 獲取兩個版本間修改的文件信息列表
     *
     * @param $fromVersion int
     * @param $headRevision int
     * @param $$path string
     *
     * @return array
     */
    public static function getChangedFiles($path, $fromVersion, $headRevision ){
        $files = array();
        $pipe = "|grep -i ^Index:|awk -F : '{print $2}'";
        $command = "svn diff -r {$fromVersion}:{$headRevision} $path";
        $output = self::runCmd ( $command ,$pipe);
        $files = array_merge($files, $output);
        $command = "svn diff -r {$headRevision}:{$fromVersion} $path"; //文件刪除可用逆向?qū)Ρ?BR>        $output = self::runCmd ( $command ,$pipe);
        $files = array_merge($files, $output);
        return array_unique($files);
    }
    /**
     * 獲取兩個版本間某文件修改 的內(nèi)容
     *
     * @param $filePath string
     * @param $fromVersion int
     * @param $headRevision int
     *
     * @return array
     */
    public static function getChangedInfo( $filePath, $fromVersion, $headRevision ){
        $command = "sudo svn diff -r {$fromVersion}:{$headRevision} $filePath";
        $output = self::runCmd ( $command );
        return $output;
    }
    /**
     * 查看文件內(nèi)容
     *
     * @param $filePath string
     * @param $version int
     *
     * @return array
     */
    public static function getFileContent($filePath, $version){
        $command = "sudo svn cat -r {$version} $filePath";
        $output = self::runCmd ( $command );
        return $output;
    }
    /**
     * Run a cmd and return result
     * @param $command string
     * @param $pipe string (可以增加管道對返回數(shù)據(jù)進行預篩選)
     * @return array
     */
    protected static function runCmd($command , $pipe ="") {
        $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" . $pipe, $output );
        return $output;
    }
}

相關(guān)文章

  • php中inlcude()性能對比詳解

    php中inlcude()性能對比詳解

    PHP程序員最常用的兩個函數(shù)莫過于require_once和include了,通過這兩個函數(shù),我們可以使用其他類庫中定義的類等對象。但很多人在使用包含相同目錄下的其他文件時,僅僅簡單使用下面的代碼進行文件引用
    2012-09-09
  • php實現(xiàn)簡單加入購物車功能

    php實現(xiàn)簡單加入購物車功能

    本文主要介紹了php實現(xiàn)簡單加入購物車功能的方法,具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • php使用curl獲取https請求的方法

    php使用curl獲取https請求的方法

    這篇文章主要介紹了php使用curl獲取https請求的方法,涉及curl針對https請求的操作技巧,非常具有實用價值,需要的朋友可以參考下
    2015-02-02
  • PHP CURLFile函數(shù)模擬實現(xiàn)文件上傳示例詳解

    PHP CURLFile函數(shù)模擬實現(xiàn)文件上傳示例詳解

    這篇文章主要介紹了PHP使用CURLFile函數(shù)模擬實現(xiàn)文件上傳,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2022-09-09
  • php Yii2框架創(chuàng)建定時任務方法詳解

    php Yii2框架創(chuàng)建定時任務方法詳解

    Yii2是一個基于組件、用于開發(fā)大型Web應用的高性能PHP框架,采用嚴格的OOP編寫,并有著完善的庫引用以及全面的教程,該框架提供了Web 2.0應用開發(fā)所需要的幾乎一切功能,是最有效率的PHP框架之一
    2022-09-09
  • php checkdate、getdate等日期時間函數(shù)操作詳解

    php checkdate、getdate等日期時間函數(shù)操作詳解

    PHP的日期時間函數(shù)date()中介紹了PHP日期時間函數(shù)的簡單用法,這類將介紹更多的函數(shù)來豐富我們的應用。
    2010-03-03
  • php限制ip地址范圍的方法

    php限制ip地址范圍的方法

    這篇文章主要介紹了php限制ip地址范圍的方法,涉及php操作IP地址的技巧,非常具有實用價值,需要的朋友可以參考下
    2015-03-03
  • PHP封裝的svn類使用內(nèi)置svn函數(shù)實現(xiàn)根據(jù)svn版本號導出相關(guān)文件示例

    PHP封裝的svn類使用內(nèi)置svn函數(shù)實現(xiàn)根據(jù)svn版本號導出相關(guān)文件示例

    這篇文章主要介紹了PHP封裝的svn類使用內(nèi)置svn函數(shù)實現(xiàn)根據(jù)svn版本號導出相關(guān)文件,結(jié)合實例形式分析了php封裝的svn操作類與根據(jù)版本導出相關(guān)版本文件操作技巧,需要的朋友可以參考下
    2018-06-06
  • PHP讀取文件內(nèi)容后清空文件示例代碼

    PHP讀取文件內(nèi)容后清空文件示例代碼

    這篇文章主要介紹了PHP讀取文件內(nèi)容后如何清空文件,需要的朋友可以參考下
    2014-03-03
  • PHP閉包函數(shù)詳解

    PHP閉包函數(shù)詳解

    這篇文章主要為大家詳細介紹了PHP閉包函數(shù),閉包函數(shù)沒有函數(shù)名稱,直接在function()傳入變量即可 使用時將定義的變量當作函數(shù)來處理,對PHP閉包函數(shù)感興趣的朋友可以參考一下
    2016-02-02

最新評論

东光县| 茶陵县| 巩义市| 灌云县| 赤水市| 阿拉尔市| 虎林市| 东乡县| 文山县| 石泉县| 东乌| 林甸县| 白城市| 广宗县| 镇宁| 塘沽区| 景宁| 扶风县| 张家口市| 邢台市| 湄潭县| 利川市| 淮南市| 梨树县| 柯坪县| 陕西省| 大同市| 镇安县| 平阴县| 孟津县| 伊春市| 普洱| 辰溪县| 突泉县| 林周县| 广宁县| 昌邑市| 忻州市| 宜兰市| 常宁市| 巩留县|