Browse Source

Use command -v for checking for programs

tags/v0.8.1
itismadness 6 years ago
parent
commit
ec4d49f690
2 changed files with 6 additions and 3 deletions
  1. +2
    -1
      src/Chardet.php
  2. +4
    -2
      src/Util.php

+ 2
- 1
src/Chardet.php View File

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


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




+ 4
- 2
src/Util.php View File

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


class Util { class Util {
public static function commandExists($cmd) { 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) { public static function strposArray(string $haystack, array $needles) {


Loading…
Cancel
Save