SyncCoreBatchCollection.php in CMS Content Sync 2.1.x
File
src/SyncCoreBatchCollection.php
View source
<?php
namespace Drupal\cms_content_sync;
class SyncCoreBatchCollection {
protected $operations = [];
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;
}
public function add($item, $type) {
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;
}
public function addMultiple($items, $prepend = false) {
$this->operations = $prepend ? array_merge($items, $this->operations) : array_merge($this->operations, $items);
}
public function getOperations() {
return $this->operations;
}
}