Esempio n. 1
0
 public function testCreateAndParseRootXml()
 {
     $node = new Zend_Service_SecondLife_Value_Llsd(Zend_Service_SecondLife_Value::parse(array("test" => "bla")));
     $this->assertEquals("<llsd><map><key>test</key><string>bla</string></map></llsd>", $node->toXml());
     $node->setValue(array("bla"));
     $this->assertEquals("<llsd><array><string>bla</string></array></llsd>", $node->toXml());
 }
Esempio n. 2
0
 public function registerUser($firstName, $lastName, $email, $password, $dateOfBirth, $stateLimitation = null, $startRegion = null, Zend_Service_SecondLife_Coordinate $startCoordinate = null, Zend_Service_SecondLife_Coordinate_Look $lookCoordinate = null)
 {
     $params = array('username' => $firstName, 'last_name_id' => is_int($lastName) ? $lastName : $this->getLastNameId($lastName), 'email' => $email, 'password' => $password, 'dob' => $dateOfBirth);
     if (null !== $stateLimitation) {
         if (!is_integer($stateLimitation)) {
             require_once 'Zend/Service/SecondLife/Exception.php';
             throw new Zend_Service_SecondLife_Exception(sprintf('Parameter $stateLimitation must be an integer. "%s" given', gettype($stateLimitation)));
         }
         $params['limited_to_estate'] = $stateLimitation;
     }
     if (null !== $startRegion) {
         $params['start_region_name'] = $startRegion;
         if (null !== $startCoordinate) {
             $params['start_local_x'] = $startCoordinate->getX();
             $params['start_local_y'] = $startCoordinate->getY();
             $params['start_local_z'] = $startCoordinate->getZ();
         }
         if (null !== $lookCoordinate) {
             $params['start_look_at_x'] = $lookCoordinate->getX();
             $params['start_look_at_y'] = $lookCoordinate->getY();
             $params['start_look_at_z'] = $lookCoordinate->getZ();
         }
     }
     require_once 'Zend/Service/SecondLife/Value/Llsd.php';
     $request = new Zend_Service_SecondLife_Value_Llsd($params);
     $xml = $this->_httpPost($this->getCapability('create_user'), $request->toXml());
     $result = $this->_parseResponse($xml);
     if (isset($result['agent_id'])) {
         return $result['agent_id'];
     } else {
         $errorCode = array_shift($result);
         require_once 'Zend/Service/SecondLife/Exception.php';
         throw new Zend_Service_SecondLife_Exception($this->getErrorDescription($errorCode), $errorCode);
     }
 }
Esempio n. 3
0
 public static function fromXml($value)
 {
     if (!$value instanceof SimpleXMLElement) {
         try {
             /** Ugly hack to ignore parse errors */
             $value = @new SimpleXMLElement($value);
         } catch (Exception $e) {
             require_once 'Zend/Service/SecondLife/Value/Exception.php';
             throw new Zend_Service_SecondLife_Value_Exception('Could not parse snippet');
         }
     }
     $type = $value->getName();
     switch ($type) {
         case self::SECONDLIFE_TYPE_INTEGER:
             require_once 'Zend/Service/SecondLife/Value/Integer.php';
             $secondlife_value = new Zend_Service_SecondLife_Value_Integer($value);
             break;
         case self::SECONDLIFE_TYPE_BOOLEAN:
             require_once 'Zend/Service/SecondLife/Value/Boolean.php';
             $secondlife_value = new Zend_Service_SecondLife_Value_Boolean($value);
             break;
         case self::SECONDLIFE_TYPE_STRING:
             require_once 'Zend/Service/SecondLife/Value/String.php';
             $secondlife_value = new Zend_Service_SecondLife_Value_String($value);
             break;
         case self::SECONDLIFE_TYPE_MAP:
             $collection = array();
             $values = array();
             $keys = array();
             foreach ($value->children() as $member) {
                 if ($member->getName() == 'key') {
                     $keys[] = (string) $member;
                 } else {
                     $values[] = self::fromXml($member)->getValue();
                 }
             }
             foreach ($keys as $pos => $key) {
                 $collection[$key] = $values[$pos];
             }
             require_once 'Zend/Service/SecondLife/Value/Map.php';
             $secondlife_value = new Zend_Service_SecondLife_Value_Map($collection);
             break;
         case self::SECONDLIFE_TYPE_ARRAY:
             $values = array();
             foreach ($value->children() as $member) {
                 $values[] = self::fromXml($member)->getValue();
             }
             require_once 'Zend/Service/SecondLife/Value/Array.php';
             $secondlife_value = new Zend_Service_SecondLife_Value_Array($values);
             break;
         case self::SECONDLIFE_TYPE_ROOT:
             require_once 'Zend/Service/SecondLife/Value/Llsd.php';
             $secondlife_value = new Zend_Service_SecondLife_Value_Llsd(count($value->children()) > 0 ? self::fromXml($value->children()) : null);
             break;
         case self::SECONDLIFE_TYPE_KEY:
             require_once 'Zend/Service/SecondLife/Value/Exception.php';
             throw new Zend_Service_SecondLife_Value_Exception('Type "key" cannot be used standalone');
             break;
         default:
             require_once 'Zend/Service/SecondLife/Value/Exception.php';
             throw new Zend_Service_SecondLife_Value_Exception(sprintf('Type "%s" not handled', is_object($value) ? get_class($value) : gettype($value)));
     }
     $secondlife_value->_setXml($value->asXml());
     return $secondlife_value;
 }