php-censor/PHPCI/Helper/UnixCommandExecutor.php

54 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
namespace PHPCI\Helper;
2014-05-11 17:38:33 +02:00
use Psr\Log\LogLevel;
class UnixCommandExecutor extends BaseCommandExecutor
{
/**
* Find a binary required by a plugin.
* @param string $binary
* @return null|string
*/
public function findBinary($binary)
{
2014-05-11 17:38:33 +02:00
$binaryPath = null;
if (is_string($binary)) {
$binary = array($binary);
}
2014-05-11 17:38:33 +02:00
foreach ($binary as $bin) {
$this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG);
if (is_file($this->rootDir . $bin)) {
$this->logger->log("Found in root: " . $bin, LogLevel::DEBUG);
$binaryPath = $this->rootDir . $bin;
break;
}
2014-05-11 17:38:33 +02:00
if (is_file($this->rootDir . 'vendor/bin/' . $bin)) {
$this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG);
$binaryPath = $this->rootDir . 'vendor/bin/' . $bin;
break;
}
2014-05-11 17:38:33 +02:00
$findCmdResult = trim(shell_exec('which ' . $bin));
if (!empty($findCmdResult)) {
$this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG);
$binaryPath = $findCmdResult;
break;
}
}
return $binaryPath;
}
}