Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: pass client to objects in an array #409

Merged
merged 1 commit into from
Apr 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,8 @@ protected static function __parseResponseToNewObject($response, $uri, $client) {

$rootNode = $dom->documentElement;

$obj = Recurly_Resource::__createNodeObject($rootNode);
$obj->_client = $client;
Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $obj);
$obj = Recurly_Resource::__createNodeObject($rootNode, $client);
Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $obj, $client);
if ($obj instanceof self) {
$obj->_afterParseResponse($response, $uri);
$obj->setHeaders($response->headers);
Expand All @@ -319,15 +318,15 @@ protected function __parseXmlToUpdateObject($xml)

if ($rootNode->nodeName == $this->getNodeName()) {
// update the current object
Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $this);
Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $this, $this->_client);
} else if ($rootNode->nodeName == 'errors') {
// add element to existing object
Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $this->_errors);
Recurly_Resource::__parseXmlToObject($rootNode->firstChild, $this->_errors, $this->_client);
}
$this->updateErrorAttributes();
}

protected static function __parseXmlToObject($node, &$object)
protected static function __parseXmlToObject($node, &$object, $client)
{
while ($node) {
//print "Node: {$node->nodeType} -- {$node->nodeName}\n";
Expand All @@ -343,10 +342,9 @@ protected static function __parseXmlToObject($node, &$object)
$nodeName = str_replace("-", "_", $node->nodeName);

if ($object instanceof Recurly_Pager) {
$new_obj = Recurly_Resource::__createNodeObject($node);
$new_obj->_client = $object->_client;
$new_obj = Recurly_Resource::__createNodeObject($node, $object->_client);
if (!is_null($new_obj)) {
Recurly_Resource::__parseXmlToObject($node->firstChild, $new_obj);
Recurly_Resource::__parseXmlToObject($node->firstChild, $new_obj, $object->_client);
$object->_objects[] = $new_obj;
}
$node = $node->nextSibling;
Expand All @@ -366,10 +364,10 @@ protected static function __parseXmlToObject($node, &$object)
continue;
}

$new_obj = Recurly_Resource::__createNodeObject($node);
$new_obj = Recurly_Resource::__createNodeObject($node, $client);
if (!is_null($new_obj)) {
if (is_object($new_obj) || is_array($new_obj)) {
Recurly_Resource::__parseXmlToObject($node->firstChild, $new_obj);
Recurly_Resource::__parseXmlToObject($node->firstChild, $new_obj, $client);
}
$object[] = $new_obj;
}
Expand Down Expand Up @@ -397,9 +395,9 @@ protected static function __parseXmlToObject($node, &$object)
}
} else if ($node->firstChild->nodeType == XML_ELEMENT_NODE) {
// has element children, drop in and continue parsing
$new_obj = Recurly_Resource::__createNodeObject($node);
$new_obj = Recurly_Resource::__createNodeObject($node, $object->_client);
if (!is_null($new_obj)) {
$object->$nodeName = Recurly_Resource::__parseXmlToObject($node->firstChild, $new_obj);
$object->$nodeName = Recurly_Resource::__parseXmlToObject($node->firstChild, $new_obj, $object->_client);
}
} else {
// we have a single text child
Expand Down Expand Up @@ -449,7 +447,7 @@ private static function parseErrorNode($node)
return $error;
}

private static function __createNodeObject($node)
private static function __createNodeObject($node, $client)
{
$nodeName = str_replace("-", "_", $node->nodeName);

Expand Down Expand Up @@ -478,6 +476,7 @@ private static function __createNodeObject($node)
$new_obj->_type = $typeAttribute;
}

$new_obj->_client = $client;
$href = $node->getAttribute('href');
if (!empty($href)) {
$new_obj->setHref($href);
Expand Down