SObject.php in Salesforce Suite 8.3
File
src/SObject.php
View source
<?php
namespace Drupal\salesforce;
class SObject {
protected $type;
protected $fields;
protected $id;
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'];
unset($data['attributes']);
$this->fields = [];
foreach ($data as $key => $value) {
$this->fields[$key] = $value;
}
$this->fields['Id'] = (string) $this->id;
}
public function id() {
return $this->id;
}
public function type() {
return $this->type;
}
public function fields() {
return $this->fields;
}
public function field($key) {
if (!array_key_exists($key, $this->fields)) {
throw new \Exception('Index not found');
}
return $this->fields[$key];
}
}