1: <?php
2:
3: namespace Guzzle\Service\Command\LocationVisitor\Request;
4:
5: use Guzzle\Service\Command\CommandInterface;
6: use Guzzle\Http\Message\RequestInterface;
7: use Guzzle\Service\Description\Parameter;
8:
9: 10: 11:
12: abstract class AbstractRequestVisitor implements RequestVisitorInterface
13: {
14: 15: 16: 17:
18: public function after(CommandInterface $command, RequestInterface $request) {}
19:
20: 21: 22: 23:
24: public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) {}
25:
26: 27: 28: 29: 30: 31: 32: 33:
34: protected function prepareValue($value, Parameter $param)
35: {
36: return is_array($value)
37: ? $this->resolveRecursively($value, $param)
38: : $param->filter($value);
39: }
40:
41: 42: 43: 44: 45: 46: 47: 48:
49: protected function resolveRecursively(array $value, Parameter $param)
50: {
51: foreach ($value as $name => &$v) {
52: switch ($param->getType()) {
53: case 'object':
54: if ($subParam = $param->getProperty($name)) {
55: $key = $subParam->getWireName();
56: $value[$key] = $this->prepareValue($v, $subParam);
57: if ($name != $key) {
58: unset($value[$name]);
59: }
60: } elseif ($param->getAdditionalProperties() instanceof Parameter) {
61: $v = $this->prepareValue($v, $param->getAdditionalProperties());
62: }
63: break;
64: case 'array':
65: if ($items = $param->getItems()) {
66: $v = $this->prepareValue($v, $items);
67: }
68: break;
69: }
70: }
71:
72: return $param->filter($value);
73: }
74: }
75: