private function format(Shape $shape, $value) { switch ($shape['type']) { case 'structure': $data = []; foreach ($value as $k => $v) { if ($v !== null && $shape->hasMember($k)) { $data[$shape['locationName'] ?: $k] = $this->format($shape->getMember($k), $v); } } return $data; case 'list': $items = $shape->getMember(); foreach ($value as &$v) { $data[] = $this->format($items, $v); } return $value; case 'map': $values = $shape->getValue(); foreach ($value as &$v) { $v = $this->format($values, $v); } return $value; case 'blob': return base64_encode($value); default: return $value; } }
public function parse(Shape $shape, $value) { switch ($shape['type']) { case 'structure': $target = []; foreach ($shape->getMembers() as $name => $member) { $name = $member['locationName'] ?: $name; if (isset($value[$name])) { $target[$name] = $this->parse($member, $value[$name]); } else { $target[$name] = null; // don't ignore null response values } } return $target; case 'list': $member = $shape->getMember(); $target = []; foreach ($value as $v) { $target[] = $this->parse($member, $v); } return $target; case 'map': $values = $shape->getValue(); $target = []; foreach ($value as $k => $v) { $target[$k] = $this->parse($values, $v); } return $target; case 'blob': return base64_decode($value); default: return $value; } }
/** * @dataProvider formatProvider */ public function testFormatsJson($def, $args, $result) { $j = new JsonBody(new Service([], function () { return []; })); $shape = Shape::create($def, new ShapeMap([])); $this->assertEquals($result, $j->build($shape, $args)); }
public function testCreatesNestedShapeReferences() { $s = Shape::create(['shape' => 'bar'], new ShapeMap(['bar' => ['type' => 'float']])); $this->assertInstanceOf('Vws\\Api\\Shape', $s); $this->assertEquals('float', $s->getType()); $this->assertEquals(false, $s->getMin()); $this->assertEquals(false, $s->getMax()); $this->assertEquals(false, $s->getPattern()); }
/** * @dataProvider validationProvider */ public function testValidatesInput($shape, $input, $result) { $shape = Shape::create($shape, new ShapeMap([])); $validator = new Validator(); try { call_user_func($validator, 'Foo', $shape, $input); if ($result !== true) { $this->fail('Should have failed with ' . $result); } } catch (\InvalidArgumentException $e) { if ($result === true) { throw $e; } else { $this->assertEquals($result, $e->getMessage()); } } }
protected function shapeFor(array $definition) { return isset($definition['shape']) ? $this->shapeMap->resolve($definition) : Shape::create($definition, $this->shapeMap); }
private function applyHeader(RequestInterface $request, $name, Shape $member, $value) { if ($member->getType() == 'timestamp') { $value = TimestampShape::format($value, 'rfc822'); } $request->setHeader($member['locationName'] ?: $name, $value); }
private function check_pattern(Shape $shape, $value) { if (($pattern = $shape->getPattern()) && !preg_match($pattern, $value)) { $this->addError('must match the following regular expression: ' . $pattern); } }