class SyncCoreBatchCollection in CMS Content Sync 8
Same name and namespace in other branches
- 2.1.x src/SyncCoreBatchCollection.php \Drupal\cms_content_sync\SyncCoreBatchCollection
- 2.0.x src/SyncCoreBatchCollection.php \Drupal\cms_content_sync\SyncCoreBatchCollection
Class SyncCoreBatchCollection.
Collect a number of requests to be executed as a batch operation.
Hierarchy
- class \Drupal\cms_content_sync\SyncCoreBatchCollection
Expanded class hierarchy of SyncCoreBatchCollection
File
- src/
SyncCoreBatchCollection.php, line 10
Namespace
Drupal\cms_content_syncView source
class SyncCoreBatchCollection {
protected $operations = [];
/**
* Get an existing item by ID.
*
* @param $id
* @param $type
*/
public function get($id, $type) {
foreach ($this->operations as $operation) {
if ($operation['type'] !== $type) {
continue;
}
if ($operation['item']['id'] !== $id) {
continue;
}
return $operation['item'];
}
return null;
}
/**
* Add or overwrite an item if one exists with the given ID.
*
* @param array $item
* @param string $type
*
* @return $this
*/
public function add($item, $type) {
// If an item with that ID already exists, we overwrite it.
foreach ($this->operations as &$operation) {
if ($operation['type'] !== $type) {
continue;
}
if ($operation['item']['id'] !== $item['id']) {
continue;
}
$operation['item'] = $item;
return $this;
}
$this->operations[] = [
'type' => $type,
'item' => $item,
];
return $this;
}
/**
* @param array $items
* @param bool $prepend
*/
public function addMultiple($items, $prepend = false) {
$this->operations = $prepend ? array_merge($items, $this->operations) : array_merge($this->operations, $items);
}
/**
* @return array
*/
public function getOperations() {
return $this->operations;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SyncCoreBatchCollection:: |
protected | property | ||
SyncCoreBatchCollection:: |
public | function | Add or overwrite an item if one exists with the given ID. | |
SyncCoreBatchCollection:: |
public | function | ||
SyncCoreBatchCollection:: |
public | function | Get an existing item by ID. | |
SyncCoreBatchCollection:: |
public | function |