Created
June 28, 2012 09:10
-
-
Save vglebov/3010104 to your computer and use it in GitHub Desktop.
object wrapper for PHP "exec" function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$e = Exec::withCommandLine($cmd)->launch(); | |
if ($e->getResultCode() !== 0) { | |
$message = join("\n", $e->getOutput()); | |
throw new Exception($message); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Exec{ | |
var $commandLine; | |
var $resultCode = 0; | |
var $output = array(); | |
public static function withCommandLine($commandLine){ | |
return new Exec($commandLine); | |
} | |
function __construct($commandLine) | |
{ | |
$this->commandLine = $commandLine; | |
} | |
public function launch() | |
{ | |
exec($this->commandLine, $this->output, $this->resultCode); | |
return $this; | |
} | |
public function getCommandLine() | |
{ | |
return $this->commandLine; | |
} | |
public function getResultCode() | |
{ | |
return $this->resultCode; | |
} | |
public function getOutput() | |
{ | |
return $this->output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Разработчик Руби унаследовал от Перла лучшие его качества, в частности и то, что лень дожна работать на программиста, а не против него. А разработчики PHP унаследовали не самые лучшие стороны Перла.