PHP封装的svn类使用内置svn函数实现根据svn版本号导出相关文件示例
本文实例讲述了PHP封装的svn类使用内置svn函数实现根据svn版本号导出相关文件。分享给大家供大家参考,具体如下:
_get_file_list($revision_array);
if(!empty($filelist))
{
$lbv_export=$svnPeer->_svn_export_list($filelist,'trunk889');
if(true===$lbv_export)
{
echo'导出成功';
}
else
{
echo'导出失败';
}
}
else
{
echo'获取文件列表失败';
}
/**
*php操作svn类,全部利用php内置的svn函数
*
*@authorwengxianhu
*@date2013-08-05
*/
classsvnPeer
{
/*svn用户名*/
public$svn_user='wengxianhu';
/*svn密码*/
public$svn_password='wxh025';
/*来源路径*/
public$source_path='/var/www/trunk/';
/*目标路径*/
public$dest_path='/var/www/';
/**
*构造函数
*
*@authorwengxianhu
*@date2013-08-05
*@returnvoid
*/
publicfunction__construct()
{
$this->_svn_connect();
}
/**
*配置SVN使用默认的用户名和密码
*
*@authorwengxianhu
*@date2013-08-05
*@returnvoid
*/
publicfunction_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);
}
/**
*根据svn版本号获取所有的文件路径
*
*@authorwengxianhu
*@date2013-08-05
*@paramarray$revision_array版本号列表
*@returnarray
*/
publicfunction_get_file_list($revision_array=array())
{
if(!empty($revision_array))
{
$filelist=array();
$log_list=array();
rsort($revision_array,SORT_NUMERIC);
foreach($revision_arrayas$_k=>$_v)
{
$log_list=@svn_log($this->source_path,$_v,$_v);
if(false===$log_list)
{
returnfalse;
}
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;
}
}
/**
*对多维数组进行搜索
*
*@authorwengxianhu
*@date2013-08-05
*@paramarray$parents被搜索数组
*@paramarray$searched搜索数组
*@returnboolean
*/
publicfunctionmultidimensional_search($parents=array(),$searched=array())
{
if(empty($searched)||empty($parents))
{
returnfalse;
}
foreach($parentsas$key=>$value)
{
$exists=true;
foreach($searchedas$skey=>$svalue){
$exists=($exists&&IsSet($parents[$key][$skey])&&$parents[$key][$skey]==$svalue);
}
if($exists)
{
return$key;
}
}
returnfalse;
}
/**
*根据svn版本号导出相应的文件
*
*@authorwengxianhu
*@date2013-08-05
*@paramarray$file_array文件路径名
*@paramstring$package_name包名
*@returnboolean成功为true,失败为false
*/
publicfunction_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_arrayas$_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;
}
/**
*创建文件夹
*
*@authorwengxianhu
*@date2013-08-05
*string$path文件路径(不包括文件名)
*returnvoid
*/
publicfunction_mkdirm($path)
{
if(!file_exists($path))
{
$this->_mkdirm(dirname($path));
mkdir($path,0755);
}
}
/**
*循环删除目录和文件函数
*
*@authorwengxianhu
*@date2013-08-15
*@paramstring$dirName目录路径
*returnarray
*/
publicfunctiondelDirAndFile($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);
}
}
}
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP目录操作技巧汇总》、《php文件操作总结》、《PHP常用遍历算法与技巧总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。