濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > 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)文件示例

熱門標(biāo)簽:高識(shí)別電銷機(jī)器人 寶安400電話辦理 智能外呼電銷系統(tǒng) h5 地圖標(biāo)注 哈爾濱400電話辦理到易號(hào)網(wǎng) 合肥外呼系統(tǒng)app 電銷機(jī)器人-快迭智能 拉薩打電話機(jī)器人 沈陽(yáng)人工智能電銷機(jī)器人公司

本文實(shí)例講述了PHP封裝的svn類使用內(nèi)置svn函數(shù)實(shí)現(xiàn)根據(jù)svn版本號(hào)導(dǎo)出相關(guān)文件。分享給大家供大家參考,具體如下:

?php
$revision_array = array(3099, 3339, 2573,3351); /* svn的版本號(hào) */
$svnPeer = new svnPeer();
$filelist = $svnPeer->_get_file_list($revision_array);
if (!empty($filelist))
{
  $lbv_export = $svnPeer->_svn_export_list($filelist, 'trunk889');
  if (true === $lbv_export)
  {
    echo '導(dǎo)出成功';
  }
  else
  {
    echo '導(dǎo)出失敗';
  }
}
else
{
  echo '獲取文件列表失敗';
}
/**
 * php操作svn類,全部利用php內(nèi)置的svn函數(shù)
 *
 * @author wengxianhu
 * @date 2013-08-05
 */
class svnPeer
{
  /* svn用戶名 */
  public $svn_user = 'wengxianhu';
  /* svn密碼 */
  public $svn_password = 'wxh025';
  /* 來(lái)源路徑 */
  public $source_path = '/var/www/trunk/';
  /* 目標(biāo)路徑 */
  public $dest_path = '/var/www/';
  /**
   * 構(gòu)造函數(shù)
   *
   * @author wengxianhu
   * @date 2013-08-05
   * @return void
   */
  public function __construct ()
  {
    $this->_svn_connect();
  }
  /**
   * 配置SVN使用默認(rèn)的用戶名和密碼
   *
   * @author wengxianhu
   * @date 2013-08-05
   * @return void
   */
  public function _svn_connect ()
  {
    svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, $this->svn_user);
    svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, $this->svn_password);
  }
  /**
   * 根據(jù)svn版本號(hào)獲取所有的文件路徑
   *
   * @author wengxianhu
   * @date 2013-08-05
   * @param array $revision_array 版本號(hào)列表
   * @return array
   */
  public function _get_file_list ($revision_array = array())
  {
    if (!empty($revision_array))
    {
      $filelist = array();
      $log_list = array();
      rsort($revision_array, SORT_NUMERIC);
      foreach ($revision_array as $_k=>$_v)
      {
        $log_list = @svn_log($this->source_path, $_v, $_v);
        if (false === $log_list)
        {
          return false;
        }
        else
        {
          $log_list = current($log_list);
          foreach ($log_list['paths'] as $s_k=>$s_v)
          {
            $s_v['path'] = preg_replace('/^\/[^\/]+\/(.*)$/i', '$1', $s_v['path']);
            $filetmp = $s_v['path'];
            if (is_file($this->source_path . $s_v['path']))
            {
              if (false === $this->multidimensional_search($filelist, array('filepath'=>$s_v['path'])))
              {
                $filelist[] = array(
                  'revision_no'    => $log_list['rev'],
                  'filepath'     => $s_v['path']
                );
              }
            }
          }
        }
      }
      return $filelist;
    }
  }
  /**
   * 對(duì)多維數(shù)組進(jìn)行搜索
   *
   * @author wengxianhu
   * @date 2013-08-05
   * @param array $parents 被搜索數(shù)組
   * @param array $searched 搜索數(shù)組
   * @return boolean
   */
  public function multidimensional_search ($parents = array(), $searched = array())
  {
    if (empty($searched) || empty($parents))
    {
      return false;
    }
    foreach ($parents as $key => $value)
    {
      $exists = true;
      foreach ($searched as $skey => $svalue) {
        $exists = ($exists  IsSet($parents[$key][$skey])  $parents[$key][$skey] == $svalue);
      }
      if ($exists)
      {
        return $key;
      }
    }
    return false;
  }
  /**
   * 根據(jù)svn版本號(hào)導(dǎo)出相應(yīng)的文件
   *
   * @author wengxianhu
   * @date 2013-08-05
   * @param array $file_array 文件路徑名
   * @param string $package_name 包名
   * @return boolean 成功為true,失敗為false
   */
  public function _svn_export_list ($file_array = array(), $package_name = '')
  {
    $info = true;
    $this->dest_path = $this->dest_path . $package_name;
    if (file_exists($this->dest_path))
    {
      $this->delDirAndFile($this->dest_path);
    }
    foreach ($file_array as $_k=>$_v)
    {
      $source_files = $this->source_path . $_v['filepath'];
      $dest_files = $this->dest_path . '/' . $_v['filepath'];
      $revision_no = (int)$_v['revision_no'];
      $this->_mkdirm(dirname($dest_files));
      $lbv_export = @svn_export($source_files, $dest_files, false, $revision_no);
      if (false === $lbv_export)
      {
        $info = false;
        break;
      }
    }
    return $info;
  }
  /**
   * 創(chuàng)建文件夾
   *
   * @author wengxianhu
   * @date 2013-08-05
   * string $path 文件路徑(不包括文件名)
   * return void
   */
  public function _mkdirm ($path)
  {
    if (!file_exists($path))
    {
      $this->_mkdirm(dirname($path));
      mkdir($path, 0755);
    }
  }
  /**
   * 循環(huán)刪除目錄和文件函數(shù)
   *
   * @author wengxianhu
   * @date 2013-08-15
   * @param string $dirName 目錄路徑
   * return array
   */
  public function delDirAndFile($dirName)
  {
    if ( $handle = opendir( "$dirName" ) )
    {
      while ( false !== ( $item = readdir( $handle ) ) )
      {
        if ( $item != "."  $item != ".." )
        {
          if ( is_dir( "$dirName/$item" ) )
          {
            $this->delDirAndFile( "$dirName/$item" );
          }
          else
          {
            unlink( "$dirName/$item" );
          }
        }
      }
      closedir( $handle );
      rmdir( $dirName );
    }
  }
}

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP目錄操作技巧匯總》、《php文件操作總結(jié)》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • PHP程序員玩轉(zhuǎn)Linux系列 自動(dòng)備份與SVN
  • PHP中調(diào)用SVN命令更新網(wǎng)站方法
  • PHP運(yùn)行SVN命令顯示某用戶的文件更新記錄的代碼
  • 使用PHP編寫的SVN類
  • php操作SVN版本服務(wù)器類代碼
  • php檢測(cè)useragent版本示例
  • 用ActivePHP打造版本管理系統(tǒng)

標(biāo)簽:泰州 巴中 張家口 山東 威海 成都 林芝 梅州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP封裝的svn類使用內(nèi)置svn函數(shù)實(shí)現(xiàn)根據(jù)svn版本號(hào)導(dǎo)出相關(guān)文件示例》,本文關(guān)鍵詞  PHP,封,裝的,svn,類,使用,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PHP封裝的svn類使用內(nèi)置svn函數(shù)實(shí)現(xiàn)根據(jù)svn版本號(hào)導(dǎo)出相關(guān)文件示例》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于PHP封裝的svn類使用內(nèi)置svn函數(shù)實(shí)現(xiàn)根據(jù)svn版本號(hào)導(dǎo)出相關(guān)文件示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    依兰县| 浙江省| 临泽县| 康平县| 青田县| 富顺县| 杭锦后旗| 大洼县| 建宁县| 威宁| 九龙坡区| 宜都市| 蒙城县| 沁源县| 汶川县| 武功县| 六安市| 宾川县| 鞍山市| 嘉祥县| 凤城市| 九龙县| 山东| 朝阳区| 石楼县| 青浦区| 湖北省| 黔西| 兰坪| 夹江县| 射阳县| 台湾省| 明光市| 永修县| 新乐市| 乡城县| 呼和浩特市| 宣汉县| 张家川| 浮山县| 大同市|