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


PHP ProcessExecutor::splitLines方法代码示例

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


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

示例1: guessGitVersion

 private function guessGitVersion(array $packageConfig, $path)
 {
     GitUtil::cleanEnv();
     $commit = null;
     $version = null;
     $prettyVersion = null;
     // try to fetch current version from git branch
     if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output, $path)) {
         $branches = array();
         $isFeatureBranch = false;
         // find current branch and collect all branch names
         foreach ($this->process->splitLines($output) as $branch) {
             if ($branch && preg_match('{^(?:\\* ) *(\\(no branch\\)|\\(detached from \\S+\\)|\\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
                 if ($match[1] === '(no branch)' || substr($match[1], 0, 10) === '(detached ') {
                     $version = 'dev-' . $match[2];
                     $prettyVersion = $version;
                     $isFeatureBranch = true;
                 } else {
                     $version = $this->versionParser->normalizeBranch($match[1]);
                     $prettyVersion = 'dev-' . $match[1];
                     $isFeatureBranch = 0 === strpos($version, 'dev-');
                     if ('9999999-dev' === $version) {
                         $version = $prettyVersion;
                     }
                 }
                 if ($match[2]) {
                     $commit = $match[2];
                 }
             }
             if ($branch && !preg_match('{^ *[^/]+/HEAD }', $branch)) {
                 if (preg_match('{^(?:\\* )? *(\\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
                     $branches[] = $match[1];
                 }
             }
         }
         if ($isFeatureBranch) {
             // try to find the best (nearest) version branch to assume this feature's version
             $result = $this->guessFeatureVersion($packageConfig, $version, $branches, 'git rev-list %candidate%..%branch%', $path);
             $version = $result['version'];
             $prettyVersion = $result['pretty_version'];
         }
     }
     if (!$version) {
         $result = $this->versionFromGitTags($path);
         if ($result) {
             $version = $result['version'];
             $prettyVersion = $result['pretty_version'];
         }
     }
     if (!$commit) {
         $command = 'git log --pretty="%H" -n1 HEAD';
         if (0 === $this->process->execute($command, $output, $path)) {
             $commit = trim($output) ?: null;
         }
     }
     return array('version' => $version, 'commit' => $commit, 'pretty_version' => $prettyVersion);
 }
开发者ID:neon64,项目名称:composer,代码行数:57,代码来源:VersionGuesser.php

示例2: guessGitVersion

 private function guessGitVersion(array $packageConfig, $path)
 {
     GitUtil::cleanEnv();
     // try to fetch current version from git tags
     if (0 === $this->process->execute('git describe --exact-match --tags', $output, $path)) {
         try {
             return $this->versionParser->normalize(trim($output));
         } catch (\Exception $e) {
         }
     }
     // try to fetch current version from git branch
     if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output, $path)) {
         $branches = array();
         $isFeatureBranch = false;
         $version = null;
         // find current branch and collect all branch names
         foreach ($this->process->splitLines($output) as $branch) {
             if ($branch && preg_match('{^(?:\\* ) *(\\(no branch\\)|\\(detached from \\S+\\)|\\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
                 if ($match[1] === '(no branch)' || substr($match[1], 0, 10) === '(detached ') {
                     $version = 'dev-' . $match[2];
                     $isFeatureBranch = true;
                 } else {
                     $version = $this->versionParser->normalizeBranch($match[1]);
                     $isFeatureBranch = 0 === strpos($version, 'dev-');
                     if ('9999999-dev' === $version) {
                         $version = 'dev-' . $match[1];
                     }
                 }
             }
             if ($branch && !preg_match('{^ *[^/]+/HEAD }', $branch)) {
                 if (preg_match('{^(?:\\* )? *(\\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
                     $branches[] = $match[1];
                 }
             }
         }
         if (!$isFeatureBranch) {
             return $version;
         }
         // try to find the best (nearest) version branch to assume this feature's version
         $version = $this->guessFeatureVersion($packageConfig, $version, $branches, 'git rev-list %candidate%..%branch%', $path);
         return $version;
     }
 }
开发者ID:ncusoho,项目名称:composer,代码行数:43,代码来源:VersionGuesser.php

示例3: testSplitLines

 public function testSplitLines()
 {
     $process = new ProcessExecutor();
     $this->assertEquals(array(), $process->splitLines(''));
     $this->assertEquals(array(), $process->splitLines(null));
     $this->assertEquals(array('foo'), $process->splitLines('foo'));
     $this->assertEquals(array('foo', 'bar'), $process->splitLines("foo\nbar"));
     $this->assertEquals(array('foo', 'bar'), $process->splitLines("foo\r\nbar"));
     $this->assertEquals(array('foo', 'bar'), $process->splitLines("foo\r\nbar\n"));
 }
开发者ID:neon64,项目名称:composer,代码行数:10,代码来源:ProcessExecutorTest.php

示例4: scanDir

 /**
  * Scan the directory set in $repoConfig['url']
  * and create any found packages.
  */
 protected function scanDir()
 {
     $dir = $this->repoConfig['url'];
     // make sure tilde is not escaped so it can be expanded
     // this allows '~/' followed by a path or just '~'
     if (($tilde = substr($dir, 0, 2)) === '~/' || $tilde === '~') {
         $dir = $tilde . ProcessExecutor::escape(substr($dir, strlen($tilde)));
     } else {
         $dir = ProcessExecutor::escape($dir);
     }
     // patterns specific to both plugins and themes
     // 'inflating' is a line printed by unzip which indicates which internal file we are looking at
     $patterns = ['inflating|Version|Description|Author|Author URI|License'];
     // files within the archives to look at
     $files = [];
     // look for plugins?
     if (isset($this->repoConfig['package-types']['wordpress-plugin']) || isset($this->repoConfig['package-types']['wordpress-muplugin'])) {
         $patterns[] = 'Plugin Name|Plugin URI';
         $files[] = "'*.php'";
     }
     // look for themes?
     if (isset($this->repoConfig['package-types']['wordpress-theme'])) {
         $patterns[] = 'Theme Name|Theme URI';
         $files[] = "'style.css'";
     }
     // determine if we have a depth limit
     $maxdepth = ($depth = (int) $this->repoConfig['max-depth']) > 0 ? "-maxdepth {$depth}" : '';
     // assemble the command
     // 1. `find` to get all zip files in the given directory
     // 2. echo the filename so we can capture where the zip is
     // 3. use `unzip` piped into `grep` to scan the zip for WP
     //    theme or plugin headers in style.css or *.php files,
     //    respectively, but only in the top two directories within the zip
     $cmd = "find -L {$dir} {$maxdepth} -iname '*.zip' -exec echo '{}' ';' -exec sh -c " . "\"unzip -c {} '*.php' -x '*/*/*' | grep -iE '^[ ^I*]*(" . implode('|', $patterns) . ")'\" ';'";
     // if this is using ssh, wrap the command in an ssh call instead
     if ($this->ssh) {
         $cmd = 'ssh ' . ProcessExecutor::escape($this->repoConfig['ssh']) . ' ' . ProcessExecutor::escape($cmd);
     }
     $process = new ProcessExecutor($this->io);
     // execute the command and see if the response code indicates success
     // @todo: do we need to catch any exceptions here?
     if (($code = $process->execute($cmd, $output)) === 0) {
         // store details about each of the files, which may be used to create a package
         $files = [];
         $zipFile = null;
         $fileName = null;
         // parse the response line-by-line to pluck out the header information
         foreach ($process->splitLines($output) as $line) {
             // is this a new zip file?
             if (strtolower(substr($line, -4)) === '.zip') {
                 $zipFile = $line;
                 // is this a new internal file?
             } else {
                 if (preg_match('/^\\s*inflating:\\s*(.+?)\\s*$/i', $line, $matches)) {
                     $fileName = $matches[1];
                 } else {
                     // parse the line for information
                     if (preg_match('/^[\\s*]*([^:]+):\\s*(.+?)\\s*$/i', $line, $matches)) {
                         // for clarity
                         list(, $property, $value) = $matches;
                         $files[$zipFile][$fileName][$property] = $value;
                     }
                 }
             }
         }
         // take the header information and create packages!
         foreach ($files as $url => $packages) {
             // we will only consider zips that have one package inside
             if (count($packages) === 1) {
                 // make sure all the keys are consistent
                 $headers = array_change_key_case(reset($packages), CASE_LOWER);
                 // file within the zip where the headers were found
                 $fileName = key($packages);
                 // the info used to create the package
                 $package = [];
                 // we have a theme!
                 if (!empty($headers['theme name'])) {
                     $package['type'] = 'wordpress-theme';
                     $name = Util::slugify($headers['theme name']);
                     $name = Util::callFilter($this->repoConfig['name-filter'], $name, $url, $fileName, $headers);
                     if (!empty($headers['theme uri'])) {
                         $package['homepage'] = $headers['theme uri'];
                     }
                     // we have a plugin!
                 } else {
                     if (!empty($headers['plugin name'])) {
                         $package['type'] = 'wordpress-plugin';
                         // use the basename of the file where the plugin headers were as the name
                         // this is a wordpress convention, but may not always be accurate
                         // @todo: what do we do about that?
                         $name = Util::slugify($headers['plugin name']);
                         $name = Util::callFilter($this->repoConfig['name-filter'], $name, $url, $fileName, $headers);
                         if (!empty($headers['plugin uri'])) {
                             $package['homepage'] = $headers['plugin uri'];
                         }
                         // does not appear to be a theme or plugin
//.........这里部分代码省略.........
开发者ID:balbuf,项目名称:composer-wp,代码行数:101,代码来源:ZipRepository.php


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