Skip to content

Commit

Permalink
remove the use of classmap to avoid bugs in PHP SOAP library < 5.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
pwolanin committed Feb 9, 2011
1 parent c7507cf commit 957ab20
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
42 changes: 41 additions & 1 deletion lib/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ protected function __construct($config)
array(
'soap_version'=>SOAP_1_1,
'trace'=>1,
'classmap' => self::$_classmap,
//'classmap' => self::$_classmap,
)
);
}
Expand Down Expand Up @@ -521,6 +521,9 @@ public function query($zoql)

try {
$result = $this->_client->__soapCall("query", $queryWrapper, null, $this->_header);
$type = $this->extractType($zoql);
$this->buildFromClassMap($type, $result);
return $result;
} catch (SoapFault $e) {
throw new ZuoraFault('ERROR in ' . __METHOD__, $e, $this->_client->__getLastRequestHeaders(), $this->_client->__getLastRequest(), $this->_client->__getLastResponseHeaders(), $this->_client->__getLastResponse());
}
Expand Down Expand Up @@ -573,4 +576,41 @@ public static function getInstance($config)
}
return self::$_instance;
}

public function buildFromClassMap($type, &$result)
{
if (isset(self::$_classmap[$type])) {
$class = self::$_classmap[$type];
} else {
return;
}
if ($result->result->size == 0) {
return;
}
if ($result->result->size > 1) {
foreach ($result->result->records as $key => $record) {
$result->result->records[$key] = new $class;
$this->fillVariables($result->result->records[$key], $record);
}
}
else {
$vars = clone($result->result->records);
$result->result->records = new $class;
$this->fillVariables($result->result->records, $vars);
}
}

public function fillVariables(&$obj, $vars) {
foreach ($vars as $key => $value) {
$obj->$key = $value;
}
}

public function extractType($zoql)
{
if (preg_match('/from ([^\s]+)/i', $zoql, $reg)) {
return $reg[1];
}
return false;
}
}
5 changes: 5 additions & 0 deletions lib/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public function getSoapVar()
self::TYPE_NAMESPACE
);
}

public function getData()
{
return $this->_data;
}
}

0 comments on commit 957ab20

Please sign in to comment.