/** * @test */ public function arrayAppendString() { $strs = array('str1', 'str2', 'str3'); $expected = array('str1_suffix', 'str2_suffix', 'str3_suffix'); $this->assertEquals(LinfoCommon::arrayAppendString($strs, '_suffix'), $expected); }
/** * Run a command and cache its output for later * * @throws CallExtException * @param string $name name of executable to call * @param string $switches command arguments */ public function exec($name, $switches = '') { // Sometimes it is necessary to call a program with sudo $attempt_sudo = array_key_exists('sudo_apps', self::$settings) && in_array($name, self::$settings['sudo_apps']); // Have we gotten it before? if (array_key_exists($name . $switches, $this->cliCache)) { return $this->cliCache[$name . $switches]; } // Try finding the exec foreach ($this->searchPaths as $path) { // Found it; run it if (is_file($path . $name) && is_executable($path . $name)) { // Complete command, path switches and all $command = "{$path}{$name} {$switches}"; // Sudoing? $command = $attempt_sudo ? LinfoCommon::locateActualPath(LinfoCommon::arrayAppendString($this->searchPaths, 'sudo', '%2s%1s')) . ' ' . $command : $command; // Result of command $result = `{$command}`; // Increment call count self::$callCount++; // Cache that $this->cliCache[$name . $switches] = $result; // Give result return $result; } } // Never got it throw new CallExtException('Exec `' . $name . '\' not found'); }