1 | <?php |
||
44 | class Call |
||
45 | { |
||
46 | /** |
||
47 | * The CLI command to execute |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $cmd; |
||
52 | |||
53 | /** |
||
54 | * The working directory in which the call will be executed |
||
55 | * |
||
56 | * @var string|null |
||
57 | */ |
||
58 | protected $cwd; |
||
59 | |||
60 | /** |
||
61 | * Environment variables - defaults to the current environment |
||
62 | * |
||
63 | * @var array|null |
||
64 | */ |
||
65 | protected $env; |
||
66 | |||
67 | /** |
||
68 | * Factory method to create a call |
||
69 | * |
||
70 | * @param string $cmd The CLI command to execute |
||
71 | * @param string|null $cwd The working directory in which the call will be executed |
||
72 | * @param array|null $env Environment variables - defaults to the current environment |
||
73 | * @return static |
||
74 | */ |
||
75 | 175 | public static function create($cmd, $cwd = null, array $env = null) |
|
79 | |||
80 | /** |
||
81 | * Creates a new instance of a CLI call |
||
82 | * |
||
83 | * @param string $cmd The CLI command to execute |
||
84 | * @param string|null $cwd The working directory in which the call will be executed |
||
85 | * @param array|null $env Environment variables - defaults to the current environment |
||
86 | */ |
||
87 | 175 | public function __construct($cmd, $cwd = null, array $env = null) |
|
93 | |||
94 | /** |
||
95 | * Returns the CLI command |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | 175 | public function getCmd() |
|
103 | |||
104 | /** |
||
105 | * Sets the CLI command |
||
106 | * |
||
107 | * @param string $cmd The CLI command to execute |
||
108 | * @return Call |
||
109 | */ |
||
110 | 175 | public function setCmd($cmd) |
|
115 | |||
116 | /** |
||
117 | * Returns the working directory for the call |
||
118 | * |
||
119 | * @return string|null |
||
120 | */ |
||
121 | 157 | public function getCwd() |
|
125 | |||
126 | /** |
||
127 | * Sets the working directory for the call |
||
128 | * |
||
129 | * @param string|null $cwd The working directory in which the call will be executed |
||
130 | * @return Call |
||
131 | */ |
||
132 | 175 | public function setCwd($cwd) |
|
133 | { |
||
134 | 175 | if (empty($cwd)) { |
|
135 | $cwd = null; |
||
136 | } else { |
||
137 | 175 | $cwd = (string)$cwd; |
|
138 | } |
||
139 | 175 | $this->cwd = $cwd; |
|
140 | 175 | return $this; |
|
141 | } |
||
142 | |||
143 | /** |
||
144 | * Returns the environment variables for the call - if overridden |
||
145 | * |
||
146 | * @return array|null |
||
147 | */ |
||
148 | 157 | public function getEnv() |
|
152 | |||
153 | /** |
||
154 | * Sets the environment variables for the call |
||
155 | * |
||
156 | * @param array|null $env Environment variables - defaults to the current environment |
||
157 | * @return Call |
||
158 | */ |
||
159 | 175 | public function setEnv(array $env = null) |
|
164 | |||
165 | /** |
||
166 | * Executes the call using the preconfigured command |
||
167 | * |
||
168 | * @param string|null $stdIn Content that will be piped to the command |
||
169 | * @return CallResult |
||
170 | * @throws \RuntimeException If the command cannot be executed |
||
171 | */ |
||
172 | 157 | public function execute($stdIn = null) |
|
204 | } |
||
205 | |||
206 |