当前位置: 首页>>代码示例>>PHP>>正文


PHP ExecFuture::getCommand方法代码示例

本文整理汇总了PHP中ExecFuture::getCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP ExecFuture::getCommand方法的具体用法?PHP ExecFuture::getCommand怎么用?PHP ExecFuture::getCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExecFuture的用法示例。


在下文中一共展示了ExecFuture::getCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getOpCodes

 public function getOpCodes()
 {
     $op_codes = array();
     $file_a = new TempFile();
     $file_b = new TempFile();
     Filesystem::writeFile($file_a, implode('', $this->a));
     Filesystem::writeFile($file_b, implode('', $this->b));
     $diff_future = new ExecFuture('diff -U0 %s %s', $file_a, $file_b);
     list($err, $stdout, $stderr) = $diff_future->resolve();
     if (!in_array($err, array(0, 1))) {
         throw new CommandException(pht('`diff` returned unexpected exit code %d', $err), $diff_future->getCommand(), $err, $stdout, $stderr);
     }
     foreach (phutil_split_lines($stdout) as $line) {
         $matches = null;
         $regexp = '/^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@/';
         if (!preg_match($regexp, $line, $matches)) {
             continue;
         }
         // We need to:
         // - normalize indices; the ones we get from `diff` are 1-indexed.
         // - account for how `diff` represents empty hunks -- essentially, it
         //   attributes the change to the *previous line* (which may be 0!). This
         //   differs from Python's difflib.
         //
         // http://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html:
         //     If a hunk contains just one line, only its start line number
         //     appears.  Otherwise its line numbers look like 'start,count'. An
         //     empty hunk is considered to start at the line that follows the
         //     hunk.
         //
         //     If a hunk and its context contain two or more lines, its line
         //     numbers look like 'start,count'. Otherwise only its end line
         //     number appears.  An empty hunk is considered to end at the line
         //     that precedes the hunk.
         $i = (int) $matches[1] - 1;
         $j = (int) $matches[3] - 1;
         if (isset($matches[2]) && $matches[2] !== '') {
             $li = (int) $matches[2];
         } else {
             $li = 1;
         }
         if (isset($matches[4]) && $matches[4] !== '') {
             $lj = (int) $matches[4];
         } else {
             $lj = 1;
         }
         if (!($li || $lj)) {
             throw new CommandException(pht('Malformed output from `diff`.'), $diff_future->getCommand(), $err, $stdout, $stderr);
         }
         if ($li === 0) {
             $op_codes[] = array('insert', $i + 1, $i + 1, $j, $j + $lj);
         } else {
             if ($lj === 0) {
                 $op_codes[] = array('delete', $i, $i + $li, $j, $j);
             } else {
                 $op_codes[] = array('replace', $i, $i + $li, $j, $j + $lj);
             }
         }
     }
     return $op_codes;
 }
开发者ID:nickhutchinson,项目名称:morefas-phabricator,代码行数:61,代码来源:FnSequenceMatcher.php


注:本文中的ExecFuture::getCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。