欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2018年06月26日 10:59:06   作者:小虎的碼農(nóng)博客  
這篇文章主要介紹了PHP封裝的svn類使用內(nèi)置svn函數(shù)實現(xiàn)根據(jù)svn版本號導(dǎo)出相關(guān)文件,結(jié)合實例形式分析了php封裝的svn操作類與根據(jù)版本導(dǎo)出相關(guān)版本文件操作技巧,需要的朋友可以參考下

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

<?php
$revision_array = array(3099, 3339, 2573,3351); /* svn的版本號 */
$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';
  /* 來源路徑 */
  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版本號獲取所有的文件路徑
   *
   * @author wengxianhu
   * @date 2013-08-05
   * @param array $revision_array 版本號列表
   * @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;
    }
  }
  /**
   * 對多維數(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版本號導(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è)計算法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

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

相關(guān)文章

最新評論