getConfig = Config::default('ZN\Prompt\PromptDefaultConfiguration')::get('Services', 'processor'); $this->driver = $this->getConfig['driver']; } /** * Sapi Name * * @return string */ public function type() : string { switch( $name = substr($sapi = php_sapi_name(), 0, 3) ) { case 'cli' : case 'cgi' : return $name; default : return $sapi; // @codeCoverageIgnore } } /** * Execute * * @param string $command * * @return string|false */ public function exec($command) { switch( $this->driver ) { case 'exec': $return = exec($command, $this->output, $this->return); break; case 'shell_exec': case 'shell' : $return = shell_exec($command); $this->output = $this->_split($return); $this->return = 0; break; case 'system': $return = Buffering\Callback::do(function() use($command) {system($command, $this->return);}); $this->output = $this->_split($return); break; } $this->driver = NULL; return $return ?? false; } /** * Select Driver * * @param string $driver * * @return Processor */ public function driver(string $driver) : Processor { $this->driver = $driver; return $this; } /** * Output * * @return array */ public function output() : array { return (array) $this->output; } /** * Return * * @return int */ public function return() : int { return (int) $this->return; } /** * Protected Split */ protected function _split($string) { return explode("\n", rtrim($string, "\n")); } }