検索
ホームページバックエンド開発PHPチュートリアルPHP_PHP で書かれた SVN クラスのチュートリアル

PHP_PHP で書かれた SVN クラスのチュートリアル

Jul 21, 2016 pm 03:00 PM
@phpsvnコード使用注文コピー外部の親切

コードをコピーします コードは次のとおりです:

/**
 * 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 ( "
", $output );
if (strpos ( $output, 'そのリビジョンには存在しない' )) {
return false;
}
return "
" 。 $コマンド 。 "
" 。 $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 ( "
", $output );
if (strpos ( $output, 'コミットされたリビジョン' )) {
return true ;
}

」を返す。 $コマンド 。 "
" 。 $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 ( '
', $output );
if (strpos ( $output, 'コミットされたリビジョン' )) {
return true;
}
戻る"
" 。 $コマンド 。 "
" 。 $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 ( '
', $output );
if (strpos ( $output, 'コミットされたリビジョン' )) {
return true ;
}

」を返す。 $コマンド 。 「
」 。 $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 ( '
', $output );
if (strpos ( $output, 'コミットされたリビジョン' )) {
return true;
}
"
" を返す。 $コマンド 。 「
」 。 $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 ( '
', $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 ( '
', $output );
if (strstr ( $output, 'チェックアウトされたリビジョン' ) ) {
return true;
}
return "
" 。 $コマンド 。 「
」 。 $output;
}
/**
* svn update
* @param $path string
    */
public static function update($path) {
$command = "cd $path && sudo svn up";
$output = self::runCmd ( $command ) ;
$output = implode ( '
', $output );
preg_match_all ( "/[0-9]+/", $output, $ret );
if (! $ret [0] [0]) {

」を返す。 $コマンド 。 「
」 。 $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 ( '
', self::runCmd ( $command ) );
if (strstr ( $output, 'テキストの競合' )) {
return 'コマンド: ' 。 $コマンド 。 '
' 。 $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 ( '
', self::runCmd ( $command ) );
if (strpos ( $output, 'コミットされたリビジョン' ) || empty ( $output )) {
return true;
}
return $output;
}
/**
* svn status (WC内のファイルやディレクトリの状態を出力)
*/
public static function getStatus($dir) {
$command = "cd $dir && sudo svn st";
自分自身を返す: :runCmd ( $command );
}
/**
* SVN の競合
*
* @param $dir string
*/
public static function hasConflict($dir) {
$output = self::getStatus ( $dir );
foreach ( $output as $line ) {
if ( substr (rim( $ line ), 0, 1 ) == 'C' || (substr (rim ( $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 == 'リビジョン' ) {
return $value;
}
}
}
/**
* 最新のバージョン番号を取得します
* @param $path string
*/
public static function getHeadRevision($path) {
$command = "cd $path && sudo svn up";
$output = self::runCmd ( $command );
$output = implode ( '
', $output );
preg_match_all ( " /[0-9]+/", $output, $ret );
if (! $ret [0] [0]) {
return "
" 。 $コマンド 。 「
」 。 $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]);
}
/**
* 2つのバージョンの間に変更されたファイル情報のリストを取得します *
*/
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"; //文件删除可用逆对比
$output = self::runCmd ( $command ,$pipe);
$files = array_merge($files, $output);
return array_unique($files);
}
/**
* 2 つのバージョン間で変更されたファイルの内容を取得します
*
* @param $filePath string
* @param $fromVersion int
」*/
public static function getChangedInfo( $filePath, $fromVersion, $headRevision ){
$command = "sudo svn diff -r {$fromVersion}:{$headRevision} $filePath";
$output = self::runCmd ( $command );
return $output;
}
/**
*ファイルコンテンツの表示*/
public static function getFileContent($filePath, $version){
$command = "sudo svn cat -r {$version} $filePath";
$output = self::runCmd ( $command );
return $output;
}
/**
* cmdを実行してreturnresults
* @param $ commandstring
* @param $ pipe string(パイプラインを追加することができます。*/
保護された静的関数 runCmd($command , $pipe ="") {
$authCommand = ' --username ' . self::SVN_USERNAME 。 self::SVN_PASSWORD 。 「 --no-auth-cache --non-interactive --config-dir 」。 self::SVN_CONFIG_DIR 。 '.subversion';
exec ( $command . $authCommand . " 2>&1" . $pipe, $output );
return $output;
}
}






http://www.bkjia.com/PHPjc/328034.html

www.bkjia.com

tru​​e

http://www.bkjia.com/PHPjc/328034.html技術記事

复制代码代码如下: ?php /*** SVN 外部コマンド クラス * * @authorrubekid * * @todo コメントには SVN コミットにラッシュを追加する必要があります **/ class SvnUtils { /*** * SVN アカウント*/ const SV...
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
PHPセッションの概念を簡単に説明してください。PHPセッションの概念を簡単に説明してください。Apr 26, 2025 am 12:09 AM

phpssionsStrackuserdataacrossmultiplepagerequestsusingauniqueidstoredinacookie.here'showtomanageetheemefectively:1)Startassession withsession_start()andstoredatain $ _ session.2)RegeneratesseSsessidafterloginwithsession_id(the topreventes_id)

PHPセッションに保存されているすべての値をどのようにループしますか?PHPセッションに保存されているすべての値をどのようにループしますか?Apr 26, 2025 am 12:06 AM

PHPでは、次の手順を通じてセッションデータを繰り返すことができます。1。session_start()を使用してセッションを開始します。 2。$ _Sessionアレイのすべてのキー価値ペアを介してforeachループを反復します。 3.複雑なデータ構造を処理する場合、is_array()またはis_object()関数を使用し、print_r()を使用して詳細情報を出力します。 4.トラバーサルを最適化する場合、ページングを使用して、一度に大量のデータの処理を避けることができます。これにより、実際のプロジェクトでPHPセッションデータをより効率的に管理および使用するのに役立ちます。

ユーザー認証にセッションを使用する方法を説明します。ユーザー認証にセッションを使用する方法を説明します。Apr 26, 2025 am 12:04 AM

このセッションは、サーバー側の状態管理メカニズムを介してユーザー認証を実現します。 1)セッションの作成と一意のIDの生成、2)IDはCookieを介して渡されます。3)サーバーストアとIDを介してセッションデータにアクセスします。

PHPセッションにユーザーの名前を保存する方法の例を挙げてください。PHPセッションにユーザーの名前を保存する方法の例を挙げてください。Apr 26, 2025 am 12:03 AM

tostoreauser'snameInappession、starthessession withsession_start()、thensignthenameto $ _session ['username']。1)ousession_start()toinitializethessession.2)assighttheuser'snameto $ _ session ['username']

PHPセッションを失敗させる可能性のあるいくつかの一般的な問題は何ですか?PHPセッションを失敗させる可能性のあるいくつかの一般的な問題は何ですか?Apr 25, 2025 am 12:16 AM

PHPSESSIONの障害の理由には、構成エラー、Cookieの問題、セッションの有効期限が含まれます。 1。構成エラー:正しいセッションをチェックして設定します。save_path。 2.Cookieの問題:Cookieが正しく設定されていることを確認してください。 3.セッションの有効期限:セッションを調整してください。GC_MAXLIFETIME値はセッション時間を延長します。

PHPでセッション関連の問題をどのようにデバッグしますか?PHPでセッション関連の問題をどのようにデバッグしますか?Apr 25, 2025 am 12:12 AM

PHPでセッションの問題をデバッグする方法は次のとおりです。1。セッションが正しく開始されるかどうかを確認します。 2.セッションIDの配信を確認します。 3.セッションデータのストレージと読み取りを確認します。 4.サーバーの構成を確認します。セッションIDとデータを出力し、セッションファイルのコンテンツを表示するなど、セッション関連の問題を効果的に診断して解決できます。

session_start()が複数回呼び出されるとどうなりますか?session_start()が複数回呼び出されるとどうなりますか?Apr 25, 2025 am 12:06 AM

session_start()への複数の呼び出しにより、警告メッセージと可能なデータ上書きが行われます。 1)PHPは警告を発し、セッションが開始されたことを促します。 2)セッションデータの予期しない上書きを引き起こす可能性があります。 3)session_status()を使用してセッションステータスを確認して、繰り返しの呼び出しを避けます。

PHPでセッションのライフタイムをどのように構成しますか?PHPでセッションのライフタイムをどのように構成しますか?Apr 25, 2025 am 12:05 AM

PHPでのセッションライフサイクルの構成は、session.gc_maxlifetimeとsession.cookie_lifetimeを設定することで達成できます。 1)session.gc_maxlifetimeサーバー側のセッションデータのサバイバル時間を制御します。 0に設定すると、ブラウザが閉じているとCookieが期限切れになります。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール