<?<span php </span><span /*</span><span * * SVN 外部命令 类 * * @author rubekid * * @todo comment need addslashes for svn commit * </span><span */</span> <span class</span><span SvnUtils { </span><span /*</span><span * * * svn 账号 </span><span */</span> <span const</span> SVN_USERNAME = "robot"<span ; </span><span /*</span><span * * svn 密码 </span><span */</span> <span const</span> SVN_PASSWORD = "robot2013"<span ; </span><span /*</span><span * * 配置文件目录 (任意指定一个临时目录,解决svn: warning: Can't open file '/root/.subversion/servers': Permission denied) </span><span */</span> <span const</span> SVN_CONFIG_DIR = "/var/tmp/"<span ; </span><span /*</span><span * * svn list * * @param $repository string * @return boolean * </span><span */</span> <span public</span> <span static</span> <span function</span> ls(<span $repository</span><span ) { </span><span $command</span> = "sudo svn ls " . <span $repository</span><span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $output</span> = <span implode</span> ( "<br />", <span $output</span><span ); </span><span if</span> (<span strpos</span> ( <span $output</span>, 'non-existent in that revision'<span )) { </span><span return</span> <span false</span><span ; } </span><span return</span> "<br />" . <span $command</span> . "<br />" . <span $output</span><span ; } </span><span /*</span><span * * svn copy * * @param $src string * @param $dst string * @param $comment string * @return boolean * </span><span */</span> <span public</span> <span static</span> <span function</span> <span copy</span>(<span $src</span>, <span $dst</span>, <span $comment</span><span ) { </span><span $command</span> = "sudo svn cp <span $src</span> <span $dst</span> -m '<span $comment</span>'"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $output</span> = <span implode</span> ( "<br />", <span $output</span><span ); </span><span if</span> (<span strpos</span> ( <span $output</span>, 'Committed revision'<span )) { </span><span return</span> <span true</span><span ; } </span><span return</span> "<br />" . <span $command</span> . "<br />" . <span $output</span><span ; } </span><span /*</span><span * * svn delete * * @param $url string * @param $comment string * @return boolean * </span><span */</span> <span public</span> <span static</span> <span function</span> delete(<span $url</span>, <span $comment</span><span ) { </span><span $command</span> = "sudo svn del <span $url</span> -m '<span $comment</span>'"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $output</span> = <span implode</span> ( '<br />', <span $output</span><span ); </span><span if</span> (<span strpos</span> ( <span $output</span>, 'Committed revision'<span )) { </span><span return</span> <span true</span><span ; } </span><span return</span> "<br />" . <span $command</span> . "<br />" . <span $output</span><span ; } </span><span /*</span><span * * svn move * * @param $src string * @param $dst string * @param $comment string * @return boolean </span><span */</span> <span public</span> <span static</span> <span function</span> move(<span $src</span>, <span $dst</span>, <span $comment</span><span ) { </span><span $command</span> = "sudo svn mv <span $src</span> <span $dst</span> -m '<span $comment</span>'"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $output</span> = <span implode</span> ( '<br />', <span $output</span><span ); </span><span if</span> (<span strpos</span> ( <span $output</span>, 'Committed revision'<span )) { </span><span return</span> <span true</span><span ; } </span><span return</span> "<br />" . <span $command</span> . "<br />" . <span $output</span><span ; } </span><span /*</span><span * * svn mkdir * * @param $url string * @param $comment string * @return boolean </span><span */</span> <span public</span> <span static</span> <span function</span> <span mkdir</span>(<span $url</span>, <span $comment</span><span ) { </span><span $command</span> = "sudo svn mkdir <span $url</span> -m '<span $comment</span>'"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $output</span> = <span implode</span> ( '<br />', <span $output</span><span ); </span><span if</span> (<span strpos</span> ( <span $output</span>, 'Committed revision'<span )) { </span><span return</span> <span true</span><span ; } </span><span return</span> "<br />" . <span $command</span> . "<br />" . <span $output</span><span ; } </span><span /*</span><span * * svn diff * @param $pathA string * @param $pathB string * @return string </span><span */</span> <span public</span> <span static</span> <span function</span> diff(<span $pathA</span>, <span $pathB</span><span ) { </span><span $output</span> = self::runCmd ( "sudo svn diff <span $pathA</span> <span $pathB</span>"<span ); </span><span return</span> <span implode</span> ( '<br />', <span $output</span><span ); } </span><span /*</span><span * * svn checkout * @param $url string * @param $dir string * @return boolean </span><span */</span> <span public</span> <span static</span> <span function</span> checkout(<span $url</span>, <span $dir</span><span ) { </span><span $command</span> = "cd <span $dir</span> && sudo svn co <span $url</span>"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $output</span> = <span implode</span> ( '<br />', <span $output</span><span ); </span><span if</span> (<span strstr</span> ( <span $output</span>, 'Checked out revision'<span )) { </span><span return</span> <span true</span><span ; } </span><span return</span> "<br />" . <span $command</span> . "<br />" . <span $output</span><span ; } </span><span /*</span><span * * svn update * @param $path string </span><span */</span> <span public</span> <span static</span> <span function</span> update(<span $path</span><span ) { </span><span $command</span> = "cd <span $path</span> && sudo svn up"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $output</span> = <span implode</span> ( '<br />', <span $output</span><span ); </span><span preg_match_all</span> ( "/[0-9]+/", <span $output</span>, <span $ret</span><span ); </span><span if</span> (! <span $ret</span> [0] [0<span ]) { </span><span return</span> "<br />" . <span $command</span> . "<br />" . <span $output</span><span ; } </span><span return</span> <span $ret</span> [0] [0<span ]; } </span><span /*</span><span * * svn merge * * @param $revision string * @param $url string * @param $dir string * * @return boolean </span><span */</span> <span public</span> <span static</span> <span function</span> merge(<span $revision</span>, <span $url</span>, <span $dir</span><span ) { </span><span $command</span> = "cd <span $dir</span> && sudo svn merge -r1:<span $revision</span> <span $url</span>"<span ; </span><span $output</span> = <span implode</span> ( '<br />', self::runCmd ( <span $command</span><span ) ); </span><span if</span> (<span strstr</span> ( <span $output</span>, 'Text conflicts'<span )) { </span><span return</span> 'Command: ' . <span $command</span> . '<br />' . <span $output</span><span ; } </span><span return</span> <span true</span><span ; } </span><span /*</span><span * * svn commit * * @param $dir string * @param $comment string * * @return boolean </span><span */</span> <span public</span> <span static</span> <span function</span> commit(<span $dir</span>, <span $comment</span><span ) { </span><span $command</span> = "cd <span $dir</span> && sudo svn commit -m'<span $comment</span>'"<span ; </span><span $output</span> = <span implode</span> ( '<br />', self::runCmd ( <span $command</span><span ) ); </span><span if</span> (<span strpos</span> ( <span $output</span>, 'Committed revision' ) || <span empty</span> ( <span $output</span><span )) { </span><span return</span> <span true</span><span ; } </span><span return</span> <span $output</span><span ; } </span><span /*</span><span * * svn status (输出WC中文件和目录的状态) * * @param $dir string </span><span */</span> <span public</span> <span static</span> <span function</span> getStatus(<span $dir</span><span ) { </span><span $command</span> = "cd <span $dir</span> && sudo svn st"<span ; </span><span return</span> self::runCmd ( <span $command</span><span ); } </span><span /*</span><span * * svn 冲突 * * @param $dir string * @return boolean </span><span */</span> <span public</span> <span static</span> <span function</span> hasConflict(<span $dir</span><span ) { </span><span $output</span> = self::getStatus ( <span $dir</span><span ); </span><span foreach</span> ( <span $output</span> <span as</span> <span $line</span><span ) { </span><span if</span> ( <span substr</span> ( <span trim</span> ( <span $line</span> ), 0, 1 ) == 'C' || (<span substr</span> ( <span trim</span> ( <span $line</span> ), 0, 1 ) == '!'<span )) { </span><span return</span> <span true</span><span ; } } </span><span return</span> <span false</span><span ; } </span><span /*</span><span * * svn log * * @param $path string * @return string * </span><span */</span> <span public</span> <span static</span> <span function</span> getLog(<span $path</span><span ) { </span><span $command</span> = "sudo svn log <span $path</span> --xml"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span return</span> <span implode</span> ( '', <span $output</span><span ); } </span><span /*</span><span * * svn info * @param $path string </span><span */</span> <span public</span> <span static</span> <span function</span> getPathRevision(<span $path</span><span ) { </span><span $command</span> = "sudo svn info <span $path</span> --xml"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $string</span> = <span implode</span> ( '', <span $output</span><span ); </span><span $xml</span> = <span new</span> SimpleXMLElement ( <span $string</span><span ); </span><span foreach</span> ( <span $xml</span>->entry [0]->attributes () <span as</span> <span $key</span> => <span $value</span><span ) { </span><span if</span> ( <span $key</span> == 'revision'<span ) { </span><span return</span> <span $value</span><span ; } } } </span><span /*</span><span * * 获取最新版本号 * @param $path string </span><span */</span> <span public</span> <span static</span> <span function</span> getHeadRevision(<span $path</span><span ) { </span><span $command</span> = "cd <span $path</span> && sudo svn up"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span $output</span> = <span implode</span> ( '<br />', <span $output</span><span ); </span><span preg_match_all</span> ( "/[0-9]+/", <span $output</span>, <span $ret</span><span ); </span><span if</span> (! <span $ret</span> [0] [0<span ]) { </span><span return</span> "<br />" . <span $command</span> . "<br />" . <span $output</span><span ; } </span><span return</span> <span $ret</span> [0] [0<span ]; } </span><span /*</span><span * * 获取某文件最早版本号 * * @param $filePath string * </span><span */</span> <span public</span> <span static</span> <span function</span> getFileFirstVersion(<span $filePath</span><span ){ </span><span $command</span> = "sudo svn log {<span $filePath</span>}"<span ; </span><span $output</span> = self::runCmd ( <span $command</span> , "|grep -i ^r[0-9]* |awk '{print $1}'"<span ); </span><span if</span>(<span empty</span>(<span $output</span><span )){ </span><span return</span> <span false</span><span ; } </span><span return</span> <span str_replace</span>("r", '', <span $output</span>[<span count</span>(<span $output</span>)-1<span ]); } </span><span /*</span><span * * 获取两个版本间修改的文件信息列表 * * @param $fromVersion int * @param $headRevision int * @param $$path string * * @return array </span><span */</span> <span public</span> <span static</span> <span function</span> getChangedFiles(<span $path</span>, <span $fromVersion</span>, <span $headRevision</span><span ){ </span><span $files</span> = <span array</span><span (); </span><span $pipe</span> = "|grep -i ^Index:|awk -F : '{print $2}'"<span ; </span><span $command</span> = "svn diff -r {<span $fromVersion</span>}:{<span $headRevision</span>} <span $path</span>"<span ; </span><span $output</span> = self::runCmd ( <span $command</span> ,<span $pipe</span><span ); </span><span $files</span> = <span array_merge</span>(<span $files</span>, <span $output</span><span ); </span><span $command</span> = "svn diff -r {<span $headRevision</span>}:{<span $fromVersion</span>} <span $path</span>"; <span //</span><span 文件删除可用逆向对比</span> <span $output</span> = self::runCmd ( <span $command</span> ,<span $pipe</span><span ); </span><span $files</span> = <span array_merge</span>(<span $files</span>, <span $output</span><span ); </span><span return</span> <span array_unique</span>(<span $files</span><span ); } </span><span /*</span><span * * 获取两个版本间某文件修改 的内容 * * @param $filePath string * @param $fromVersion int * @param $headRevision int * * @return array </span><span */</span> <span public</span> <span static</span> <span function</span> getChangedInfo( <span $filePath</span>, <span $fromVersion</span>, <span $headRevision</span><span ){ </span><span $command</span> = "sudo svn diff -r {<span $fromVersion</span>}:{<span $headRevision</span>} <span $filePath</span>"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span return</span> <span $output</span><span ; } </span><span /*</span><span * * 查看文件内容 * * @param $filePath string * @param $version int * * @return array </span><span */</span> <span public</span> <span static</span> <span function</span> getFileContent(<span $filePath</span>, <span $version</span><span ){ </span><span $command</span> = "sudo svn cat -r {<span $version</span>} <span $filePath</span>"<span ; </span><span $output</span> = self::runCmd ( <span $command</span><span ); </span><span return</span> <span $output</span><span ; } </span><span /*</span><span * * Run a cmd and return result * @param $command string * @param $pipe string (可以增加管道对返回数据进行预筛选) * @return array </span><span */</span> <span protected</span> <span static</span> <span function</span> runCmd(<span $command</span> , <span $pipe</span> =""<span ) { </span><span $authCommand</span> = ' --username ' . self::SVN_USERNAME . ' --password ' . self::SVN_PASSWORD . ' --no-auth-cache --non-interactive --config-dir ' . self::SVN_CONFIG_DIR . '.subversion'<span ; </span><span exec</span> ( <span $command</span> . <span $authCommand</span> . " 2>&1" . <span $pipe</span>, <span $output</span><span ); </span><span return</span> <span $output</span><span ; } }</span>

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version
Visual web development tools
