class SObject in Salesforce Suite 8.3
Same name and namespace in other branches
- 8.4 src/SObject.php \Drupal\salesforce\SObject
- 5.0.x src/SObject.php \Drupal\salesforce\SObject
Class SObject.
@package Drupal\salesforce
Hierarchy
- class \Drupal\salesforce\SObject
Expanded class hierarchy of SObject
15 files declare their use of SObject
- MappedObject.php in modules/
salesforce_mapping/ src/ Entity/ MappedObject.php - MappedObjectInterface.php in modules/
salesforce_mapping/ src/ Entity/ MappedObjectInterface.php - MappedObjectTest.php in modules/
salesforce_mapping/ tests/ src/ Unit/ MappedObjectTest.php - PropertiesExtended.php in modules/
salesforce_mapping/ src/ Plugin/ SalesforceMappingField/ PropertiesExtended.php - PullBase.php in modules/
salesforce_pull/ src/ Plugin/ QueueWorker/ PullBase.php
File
- src/
SObject.php, line 10
Namespace
Drupal\salesforceView source
class SObject {
protected $type;
protected $fields;
protected $id;
/**
* SObject constructor.
*
* @param array $data
* The SObject field data.
*
* @throws \Exception
*/
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;
}
/**
* SFID Getter.
*
* @return \Drupal\salesforce\SFID
* The record id.
*/
public function id() {
return $this->id;
}
/**
* Type getter.
*
* @return string
* The object type.
*/
public function type() {
return $this->type;
}
/**
* Fields getter.
*
* @return array
* All SObject fields.
*/
public function fields() {
return $this->fields;
}
/**
* Given $key, return corresponding field value.
*
* @return mixed
* The value.
*
* @throws \Exception
* If $key is not found.
*/
public function field($key) {
if (!array_key_exists($key, $this->fields)) {
throw new \Exception('Index not found');
}
return $this->fields[$key];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SObject:: |
protected | property | ||
SObject:: |
protected | property | ||
SObject:: |
protected | property | ||
SObject:: |
public | function | Given $key, return corresponding field value. | |
SObject:: |
public | function | Fields getter. | |
SObject:: |
public | function | SFID Getter. | |
SObject:: |
public | function | Type getter. | |
SObject:: |
public | function | SObject constructor. |