瀏覽代碼

Use command -v for checking for programs

tags/v0.8.1
itismadness 6 年之前
父節點
當前提交
ec4d49f690
共有 2 個檔案被更改,包括 6 行新增3 行删除
  1. +2
    -1
      src/Chardet.php
  2. +4
    -2
      src/Util.php

+ 2
- 1
src/Chardet.php 查看文件

@@ -15,11 +15,12 @@ class Chardet {
foreach ($this->executables as $executable) {
if (Util::commandExists($executable)) {
$this->executable = $executable;
break;
}
}

if ($this->executable === null) {
throw new \RuntimeException('Chardet not installed');
throw new \RuntimeException('chardet not installed');
}
}



+ 4
- 2
src/Util.php 查看文件

@@ -4,8 +4,10 @@ namespace OrpheusNET\Logchecker;

class Util {
public static function commandExists($cmd) {
$return = shell_exec(sprintf("which %s", escapeshellarg($cmd)));
return !empty($return);
$where = substr(strtolower(PHP_OS), 0, 3) === 'win' ? 'where' : 'command -v';

exec("{$where} {$cmd} 2>/dev/null", $output, $return_var);
return $return_var === 0;
}

public static function strposArray(string $haystack, array $needles) {


Loading…
取消
儲存