Path: blob/master/src/applications/drydock/interface/command/DrydockCommandInterface.php
12262 views
<?php12abstract class DrydockCommandInterface extends DrydockInterface {34const INTERFACE_TYPE = 'command';56private $workingDirectoryStack = array();78public function pushWorkingDirectory($working_directory) {9$this->workingDirectoryStack[] = $working_directory;10return $this;11}1213public function popWorkingDirectory() {14if (!$this->workingDirectoryStack) {15throw new Exception(16pht(17'Unable to pop working directory, directory stack is empty.'));18}19return array_pop($this->workingDirectoryStack);20}2122public function peekWorkingDirectory() {23if ($this->workingDirectoryStack) {24return last($this->workingDirectoryStack);25}26return null;27}2829final public function getInterfaceType() {30return self::INTERFACE_TYPE;31}3233final public function exec($command) {34$argv = func_get_args();35$exec = call_user_func_array(36array($this, 'getExecFuture'),37$argv);38return $exec->resolve();39}4041final public function execx($command) {42$argv = func_get_args();43$exec = call_user_func_array(44array($this, 'getExecFuture'),45$argv);46return $exec->resolvex();47}4849abstract public function getExecFuture($command);5051protected function applyWorkingDirectoryToArgv(array $argv) {52$directory = $this->peekWorkingDirectory();5354if ($directory !== null) {55$cmd = $argv[0];56$cmd = "(cd %s && {$cmd})";57$argv = array_merge(58array($cmd),59array($directory),60array_slice($argv, 1));61}6263return $argv;64}6566}676869