public function SObject::__construct in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 src/SObject.php \Drupal\salesforce\SObject::__construct()
- 5.0.x src/SObject.php \Drupal\salesforce\SObject::__construct()
SObject constructor.
Parameters
array $data: The SObject field data.
File
- src/
SObject.php, line 39
Class
- SObject
- Class SObject.
Namespace
Drupal\salesforceCode
public function __construct(array $data = []) {
if (!isset($data['id']) && !isset($data['Id'])) {
throw new \Exception('Refused to instantiate SObject without ID');
}
if (isset($data['id'])) {
$data['Id'] = $data['id'];
}
$this->id = new SFID($data['Id']);
unset($data['id'], $data['Id']);
if (empty($data['attributes']) || !isset($data['attributes']['type'])) {
throw new \Exception('Refused to instantiate SObject without Type');
}
$this->type = $data['attributes']['type'];
// Attributes array also contains "url" index, which we don't need.
unset($data['attributes']);
$this->fields = [];
foreach ($data as $key => $value) {
$this->fields[$key] = $value;
}
$this->fields['Id'] = (string) $this->id;
}