public function testCommandFinder() { $this->assertInternalType('bool', \Packaged\Helpers\System::commandExists('whois')); if (\Packaged\Helpers\System::isWindows()) { $this->assertTrue(\Packaged\Helpers\System::commandExists('explorer')); } else { $this->assertTrue(\Packaged\Helpers\System::commandExists('echo')); } $this->assertFalse(\Packaged\Helpers\System::commandExists('madeupcommand2')); }
protected function runCommand($command) { $exitCode = 0; $method = $this->_executeMethod; if (System::commandExists('bash')) { // Use bash to execute if available, // enables CTRL+C to also kill spawned process (cygwin issue) $command = "bash -c '{$command}'"; } $method($command, $exitCode); return $exitCode; }
public function visitorProvider() { $whois = System::commandExists('whois'); return [['127.0.0.1', 'GB', 'London', 'eng'], ['127.0.0.1', 'UK', 'Portsmouth', 'england', new ConfigSection('http_visitor', ['city' => 'Portsmouth', 'country' => 'UK', 'region' => 'england'])], ['208.67.222.222', $whois ? 'US' : 'GB', $whois ? 'San Francisco' : 'London', $whois ? 'CA' : 'eng', new ConfigSection('http_visitor', ['whois' => true])]]; }
protected function _fromWhois() { if (System::commandExists('whois')) { exec("whois " . $this->_ip, $whois); $whois = implode("\n", $whois); $countries = $cities = $regions = []; preg_match_all('/^country:\\s*([A-Z]{2})/mi', $whois, $countries); if (isset($countries[1]) && !empty($countries[1])) { $this->_country = end($countries[1]); } preg_match_all('/^city:\\s*([A-Z].*$)/mi', $whois, $cities); if (isset($cities[1]) && !empty($cities[1])) { $this->_city = end($cities[1]); } preg_match_all('/^(state|stateprov|county|prov|province):\\s*([A-Z].*$)/mi', $whois, $regions); if (isset($regions[2]) && !empty($regions[1])) { $this->_region = end($regions[2]); } } }