Beispiel #1
0
 public function testSetupAttributeProperties()
 {
     $obj = new Dummy('foo');
     $obj->setupAttribute('buzz', A::REQUIRED, A::SINGLE);
     $this->assertTrue($obj->getAttribute('buzz')->isRequired());
     $this->assertFalse($obj->getAttribute('buzz')->isMultiple());
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * Create a dummy object using the template descriptor from the RIPE 
  * metadata service. This can be useful if the package’s attribute 
  * validation rules become outdated and you absolutely need a confomant 
  * RIPE object (and can’t wait for the update).
  * 
  * @param string $type A RIPE object type
  * @param array $descriptor A template descriptor.
  * @return Dummy A dummy object according to the descriptor.
  */
 public static function factory($type, array $descriptor)
 {
     $key = null;
     foreach ($descriptor as $attribute) {
         if (in_array('PRIMARY_KEY', $attribute['keys'])) {
             $key = $attribute['name'];
             break;
         }
     }
     $obj = new Dummy($type, $key);
     foreach ($descriptor as $attribute) {
         $required = $attribute['requirement'] === 'MANDATORY';
         $multiple = $attribute['cardinality'] === 'MULTIPLE';
         $obj->setupAttribute($attribute['name'], $required, $multiple);
     }
     return $obj;
 }