67 parent::__construct($parameters);
69 foreach ($this->operation->getParams() as $name => $arg) {
70 $currentValue = $this[$name];
71 $configValue = $arg->getValue($currentValue);
73 if ($currentValue !== $configValue) {
74 $this[$name] = $configValue;
85 unset($this[
'command.on_complete']);
90 if (!$this[self::HIDDEN_PARAMS]) {
93 self::RESPONSE_PROCESSING,
107 $this->request =
null;
108 $this->result =
null;
123 return $this->operation->getName();
138 if (!is_callable($callable)) {
142 $this->onComplete = $callable;
149 if (!$this->client) {
150 throw new CommandException(
'A client must be associated with the command before it can be executed.');
153 return $this->client->execute($this);
170 if (!$this->request) {
171 throw new CommandException(
'The command must be prepared before retrieving the request');
183 return $this->request->getResponse();
192 if (
null === $this->result) {
195 if ($this->onComplete) {
196 call_user_func($this->onComplete, $this);
212 return $this->request !==
null;
217 return $this->request !==
null && $this->request->getState() ==
'complete';
223 if (!$this->client) {
224 throw new CommandException(
'A client must be associated with the command before it can be prepared.');
228 if (!isset($this[self::RESPONSE_PROCESSING])) {
233 $this->client->dispatch(
'command.before_prepare', array(
'command' => $this));
241 if ($headers = $this[self::HEADERS_OPTION]) {
242 foreach ($headers as $key => $value) {
243 $this->request->setHeader($key, $value);
253 if ($responseBody = $this[self::RESPONSE_BODY]) {
254 $this->request->setResponseBody($responseBody);
257 $this->client->dispatch(
'command.after_prepare', array(
'command' => $this));
286 protected function init() {}
291 abstract protected function build();
300 return new Operation(array(
'name' => get_class($this)));
311 : $this->request->getResponse();
322 if ($this[self::DISABLE_VALIDATION]) {
328 foreach ($this->operation->getParams() as $name => $schema) {
329 $value = $this[$name];
331 $errors = array_merge($errors,
$validator->getErrors());
332 } elseif ($value !== $this[$name]) {
334 $this->data[$name] = $value;
341 if ($properties = $this->operation->getAdditionalParameters()) {
342 foreach ($this->
toArray() as $name => $value) {
344 if (!$this->operation->hasParam($name) && !in_array($name, $hidden)) {
346 $properties->setName($name);
347 if (!
$validator->validate($properties, $value)) {
348 $errors = array_merge($errors,
$validator->getErrors());
349 } elseif ($value !== $this[$name]) {
350 $this->data[$name] = $value;
356 if (!empty($errors)) {
358 $e->setErrors($errors);
371 if (!$this->validator) {
384 if (!$this->validator) {
388 return $this->validator->getErrors();