/** * Currently used to "get the entire payload returned by the API", as PHP arrays */ public function payloadArray() { return Bf_Util::jsonStrToAssociativeArray($this->payloadStr()); }
protected function buildEntity($class, $constructArgs, $key = NULL) { $client = $this->getClient(); $transformedToArray = NULL; if (!is_array($constructArgs)) { if (is_object($constructArgs)) { // maybe we have been given an entity already? if (method_exists($constructArgs, 'getClassName')) { $itsClass = $constructArgs->getClassName(); if ($itsClass == $class) { // use the provided entity. Hm, should we set its client to match our own? Let's not for now. return $constructArgs; } else { $thisClass = $this->getClassName(); $errorString = "Construction of entity <{$class}> inside entity <{$thisClass}> failed; expected array or <{$class}> entity. Instead received object (with class <{$itsClass}>)."; throw new Bf_UnserializationException($errorString); } } else { // this is probably a POPO, so I'll allow it. cast to associative array and continue. $transformedToArray = (array) $constructArgs; } } else { if (is_string($constructArgs) && $key === 'metadata') { // in the case of `metadata` field: it is possible that post-processing in the API failed to unserialize this JSON string into JSON. We shall take matters into our own hands. $transformedToArray = Bf_Util::jsonStrToAssociativeArray($constructArgs); } else { $itsType = gettype($constructArgs); $thisClass = $this->getClassName(); $errorString = "Construction of entity <{$class}> inside entity <{$thisClass}> failed; expected array or <{$class}> entity. Instead received: <{$constructArgs}> (with type <{$itsType}>)"; throw new Bf_UnserializationException($errorString); } } } if (!is_null($transformedToArray)) { if (!is_array($transformedToArray)) { $itsType = gettype($constructArgs); $thisClass = $this->getClassName(); $errorString = "Construction of entity <{$class}> inside entity <{$thisClass}> failed; expected array or <{$class}> entity. We identified it as a salvageable case -- and attempted to transform it into an array -- but failed. Received: <{$constructArgs}> (with type <{$itsType}>)"; throw new Bf_UnserializationException($errorString); } $constructArgs = $transformedToArray; } $newEntity = Bf_BillingEntity::constructEntityFromArgs($class, $constructArgs, $client); return $newEntity; }