検索
ホームページphp教程php手册phpはSVNクラスを操作します

PHP を使用して、コピー、リストの表示、削除、移動、ディレクトリの作成、差分の表示、更新、マージ、送信、ステータスの取得、コミット ログの取得、現在のバージョン番号の取得などの SVN 操作を実行します。 svn 1.6.11 バージョンでテストされました。

/**
*
* svn
の外部プログラムを実行するためのクラス *
* @auth Seven Yang
*
*/
クラス SvnPeer
{

/**
* リポジトリ内のディレクトリ エントリを一覧表示します
*
* @param 文字列 特定のプロジェクト リポジトリ パス
* @return bool 検証が成功した場合は true、それ以外の場合は false
*/
静的パブリック関数 ls($repository)
{
$command = "svn ls " . $repository;
$output = SvnPeer::runCmd($command);
$output = implode("
", $output);
if (strpos($output, 'そのリビジョンには存在しません')) {
false を返します;
}

"
" を返します。
}

/**
* 履歴を記憶しながら、作業コピーまたはリポジトリに何かを複製します
*
* @param $src
* @param $dst
* @param $comment 文字列でログメッセージを指定します
* @return bool true、コピーが成功した場合は、それ以外の場合はエラー メッセージを返します
*
* @todo コメントには svn commit
のラッシュを追加する必要があります*/
静的パブリック関数 copy($src, $dst, $comment)
{
$command = "svn cp $src $dst -m '$comment'";
$output = SvnPeer::runCmd($command);
$output = implode("
", $output);

if (strpos($output, 'コミットされたリビジョン')) {
true を返します;
}

"
" を返します。
}

/**
* ファイルとディレクトリをバージョン管理から削除します
*
* @param $url
* @return bool true、削除が成功した場合は、それ以外の場合はエラー メッセージを返します
*
* @todo コメントには svn commit
のラッシュを追加する必要があります*/
静的パブリック関数 delete($url, $comment)
{
$command = "svn del $url -m '$comment'";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);
if (strpos($output, 'コミットされたリビジョン')) {
true を返します;
}

"
" を返します。
}

/**
* 作業コピーまたはリポジトリ内の何かを移動および/または名前変更します
*
* @param $src 文字列トランク パス
* @param $dst string 新しい分岐パス
* @param $comment 文字列でログメッセージを指定します
* @return bool true、移動が成功した場合は、それ以外の場合はエラー メッセージを返します
*
* @todo コメントには svn commit
のラッシュを追加する必要があります*/
静的パブリック関数 move($src, $dst, $comment)
{
$command = "svn mv $src $dst -m '$comment'";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);

if (strpos($output, 'コミットされたリビジョン')) {
true を返します;
}

"
" を返します。
}

/**
* バージョン管理下に新しいディレクトリを作成します
*
* @param $url 文字列
* @param $comment 文字列 svn メッセージ
* @return bool true、作成が成功した場合は、それ以外の場合はエラー メッセージを返します
*
* @todo コメントには svn commit
のラッシュを追加する必要があります*/
静的パブリック関数 mkdir($url, $comment)
{
$command = "svn mkdir $url -m '$comment'";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);

if (strpos($output, 'コミットされたリビジョン')) {
true を返します;
}

"
" を返します。
}

静的パブリック関数 diff($pathA, $pathB)
{
$output = SvnPeer::runCmd("svn diff $pathA $pathB");
return implode('
', $output);
}

静的パブリック関数 checkout($url, $dir)
{
$command = "cd $dir && svn co $url";
$output = SvnPeer::runCmd($command);
$output = implode('
', $output);
if (strstr($output, 'チェックアウトされたリビジョン')) {
true を返します;
}

"
" を返します。
}


静的パブリック関数 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]){

」を返します。 $コマンド 。 "
" 。 $output;
}

return $ret[0][0];
}

静的パブリック関数 merge($revision, $url, $dir)
{
$command = "cd $dir && svn merge -r1:$revision $url";
$output = implode('
', SvnPeer::runCmd($command));
if (strstr($output, 'テキストの競合')) {
'コマンド: ' を返します。 $command .'
'。 $output;
}

true を返します;
}

静的パブリック関数 commit($dir, $comment)
{
$command = "cd $dir && svn commit -m'$comment'";
$output = implode('
', SvnPeer::runCmd($command));

if (strpos($output, 'コミットされたリビジョン') empty($output)) {
true を返します;
}

$output を返す;
}

静的パブリック関数 getStatus($dir)
{
$command = "cd $dir && svn st";
return SvnPeer::runCmd($command);
}

静的パブリック関数 hasConflict($dir)
{
$output = SvnPeer::getStatus($dir);
foreach ($output as $line){
if ('C' == substr(trim($line), 0, 1) ('!' == substr(trim($line), 0, 1))){
true を返します;
}
}

false を返します;
}

/**
* XML で一連のパスのログ メッセージを表示
*
* @param パス文字列
* @return ログメッセージ文字列
*/
静的パブリック関数 getLog($path)
{
$command = "svn log $path --xml";
$output = SvnPeer::runCmd($command);
return implode('', $output);
}

静的パブリック関数 getPathRevision($path)
{
$command = "svn info $path --xml";
$output = SvnPeer::runCmd($command);
$string = implode('', $output);
$xml = 新しい SimpleXMLElement($string);
foreach ($xml->entry[0]->attributes() as $key=>$value){
if ('リビジョン' == $key) {
$value を返す;
}
}
}

静的パブリック関数 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]){

」を返します。 $コマンド 。 "
" 。 $output;
}

return $ret[0][0];
}

/**
* cmd を実行し、結果を返します
*
* @param 文字列コマンドライン
* @param boolen true には SVN 認証を追加する必要があります
* @return 配列 svn が実行する出力の内容
*/
静的保護関数 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);

$output を返す;
}
}



声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、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

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

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

SecLists

SecLists

SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境