Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 public function testMultipleAttributeWithValueObject()
 {
     $attr = new Attribute('test', Attr::REQUIRED, Attr::MULTIPLE);
     $value = new AttributeValue('something');
     $value->setType('example')->setLink('http://www.example.com/something');
     $attr->addValue($value);
     $data = $attr->getValue();
     $this->assertInternalType('array', $data);
     $this->assertCount(1, $data);
     $this->assertInternalType('object', $data[0]);
 }