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

使用PHP編寫的SVN類

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

復(fù)制代碼 代碼如下:

<?php
/**
 * SVN 外部命令 類
 *
 * @author rubekid
 *
 * @todo comment need addslashes for svn commit
 *
 */
class SvnUtils {
    /**
     *
     * svn 賬號(hào)
     */
    const SVN_USERNAME = "robot";
    /**
     * svn 密碼
     */
    const SVN_PASSWORD = "robot2013";
    /**
     * 配置文件目錄   (任意指定一個(gè)臨時(shí)目錄,解決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;
            }
        }
    }
    /**
     * 獲取最新版本號(hào)
     * @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];
    }
    /**
     * 獲取某文件最早版本號(hào)
     *
     * @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]);
    }
    /**
     * 獲取兩個(gè)版本間修改的文件信息列表
     *
     * @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);
    }
    /**
     * 獲取兩個(gè)版本間某文件修改 的內(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 (可以增加管道對(duì)返回?cái)?shù)據(jù)進(jìn)行預(yù)篩選)
     * @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()性能對(duì)比詳解

    php中inlcude()性能對(duì)比詳解

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

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

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

    php使用curl獲取https請(qǐng)求的方法

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

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

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

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

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

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

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

    php限制ip地址范圍的方法

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

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

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

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

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

    PHP閉包函數(shù)詳解

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

最新評(píng)論

靖宇县| 鹤岗市| 湄潭县| 新干县| 措美县| 佛坪县| 德保县| 上栗县| 泰宁县| 桦川县| 拉孜县| 灌云县| 邯郸县| 鱼台县| 阳西县| 天镇县| 德保县| 萨嘎县| 黄骅市| 周口市| 丰宁| 高台县| 绥宁县| 白河县| 兰西县| 叙永县| 津南区| 巩义市| 若尔盖县| 珠海市| 北辰区| 杭州市| 诏安县| 丹东市| 江阴市| 西充县| 桦甸市| 莱阳市| 平塘县| 丹凤县| 青铜峡市|