public setOptions ( array $options ) : static | ||
$options | array | array of name => value options that should be applied to the object You can also pass options that use a setter, e.g. you can pass a `fileName` option which will be passed to `setFileName()`. |
리턴 | static | for method chaining |
public function setOptions($options)
{
foreach ($options as $key => $value) {
if (property_exists($this, $key)) {
$this->{$key} = $value;
} else {
$method = 'set' . ucfirst($key);
if (method_exists($this, $method)) {
call_user_func(array($this, $method), $value);
} else {
throw new \Exception("Unknown configuration option '{$key}'");
}
}
}
return $this;
}
public function testCanSetOptions() { $command = new Command(); $command->setOptions(array('command' => 'echo', 'escapeArgs' => false, 'procEnv' => array('TESTVAR' => 'test'), 'args' => '-n $TESTVAR')); $this->assertEquals('echo -n $TESTVAR', $command->getExecCommand()); $this->assertFalse($command->escapeArgs); $this->assertFalse($command->getExecuted()); $this->assertTrue($command->execute()); $this->assertTrue($command->getExecuted()); $this->assertEquals('test', $command->getOutput()); }