public function testAttributeValueToArray() { $reg = new RegObject(); $value = new AttributeValue('something'); $value->setLink('http://www.example.com/something'); $reg['source'] = 'TEST'; $reg['register'] = $value; $this->assertEquals($reg->toArray()['objects']['object'][0]['attributes']['attribute'], [['name' => 'register', 'value' => 'something'], ['name' => 'source', 'value' => 'TEST']]); }
/** * Convert the JSON response into a RPSL object. * * @param array $item The "object" array from the the response. * @return ObjectInterface */ protected function createObject($item) { $type = $item['type']; $class = __NAMESPACE__ . '\\RPSL\\' . str_replace(' ', '', ucwords(str_replace('-', ' ', $type))); if (isset($item['primary-key'])) { $pk = $item['primary-key']['attribute'][0]; } else { $pk = ['name' => null, 'value' => '']; } if (class_exists($class)) { $object = new $class($pk['value']); } else { $object = new Dummy($type, $pk['name']); } foreach ($item['attributes']['attribute'] as $value) { try { if (count($value) < 3) { $attr_val = $value['value']; } elseif ($value['name'] === 'source') { $attr_val = $value['value']; } else { $attr_val = new AttributeValue($value['value']); if (isset($value['comment'])) { $attr_val->setComment($value['comment']); } if (isset($value['referenced-type'])) { $attr_val->setType($value['referenced-type']); } if (isset($value['link']) and $value['link']['type'] === 'locator') { $attr_val->setLink($value['link']['href']); } } $object->getAttribute($value['name'])->addValue($attr_val); } catch (\Exception $e) { // skip over attributes that are present in the response but do // not conform to the current definitions continue; } } return $object; }