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

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

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

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

/**
* 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 までご連絡ください。

ホット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衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

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

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

CakePHP プロジェクトの構成 CakePHP プロジェクトの構成 Sep 10, 2024 pm 05:25 PM

この章では、CakePHP の環境変数、一般設定、データベース設定、電子メール設定について理解します。

Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Ubuntu および Debian 用の PHP 8.4 インストールおよびアップグレード ガイド Dec 24, 2024 pm 04:42 PM

PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

CakePHP の日付と時刻 CakePHP の日付と時刻 Sep 10, 2024 pm 05:27 PM

Cakephp4 で日付と時刻を操作するには、利用可能な FrozenTime クラスを利用します。

CakePHP ファイルのアップロード CakePHP ファイルのアップロード Sep 10, 2024 pm 05:27 PM

ファイルのアップロードを行うには、フォーム ヘルパーを使用します。ここではファイルアップロードの例を示します。

CakePHP ルーティング CakePHP ルーティング Sep 10, 2024 pm 05:25 PM

この章では、ルーティングに関連する次のトピックを学習します。

CakePHP について話し合う CakePHP について話し合う Sep 10, 2024 pm 05:28 PM

CakePHP は、PHP 用のオープンソース フレームワークです。これは、アプリケーションの開発、展開、保守をより簡単にすることを目的としています。 CakePHP は、強力かつ理解しやすい MVC のようなアーキテクチャに基づいています。モデル、ビュー、コントローラー

PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 PHP 開発用に Visual Studio Code (VS Code) をセットアップする方法 Dec 20, 2024 am 11:31 AM

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

CakePHP バリデータの作成 CakePHP バリデータの作成 Sep 10, 2024 pm 05:26 PM

Validator は、コントローラーに次の 2 行を追加することで作成できます。

See all articles