modules
3 weeks ago
replicastore
3 months ago
sync-queue
5 months ago
class-actions.php
1 month ago
class-activity-log-event.php
3 weeks ago
class-data-settings.php
1 month ago
class-dedicated-sender.php
7 months ago
class-default-filter-settings.php
4 years ago
class-defaults.php
2 days ago
class-functions.php
1 month ago
class-health.php
4 months ago
class-json-deflate-array-codec.php
7 months ago
class-listener.php
1 month ago
class-lock.php
4 years ago
class-main.php
2 months ago
class-modules.php
1 year ago
class-package-version.php
2 days ago
class-queue-buffer.php
4 years ago
class-queue.php
1 month ago
class-replicastore.php
1 month ago
class-rest-endpoints.php
4 months ago
class-rest-sender.php
1 month ago
class-sender.php
1 month ago
class-server.php
4 months ago
class-settings.php
3 months ago
class-simple-codec.php
7 months ago
class-users.php
3 months ago
class-utils.php
4 years ago
interface-codec.php
4 years ago
interface-replicastore.php
1 month ago
class-queue-buffer.php
79 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Sync queue buffer. |
| 4 | * |
| 5 | * @package automattic/jetpack-sync |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Sync; |
| 9 | |
| 10 | /** |
| 11 | * A buffer of items from the queue that can be checked out. |
| 12 | */ |
| 13 | class Queue_Buffer { |
| 14 | /** |
| 15 | * Sync queue buffer ID. |
| 16 | * |
| 17 | * @access public |
| 18 | * |
| 19 | * @var int |
| 20 | */ |
| 21 | public $id; |
| 22 | |
| 23 | /** |
| 24 | * Sync items. |
| 25 | * |
| 26 | * @access public |
| 27 | * |
| 28 | * @var array |
| 29 | */ |
| 30 | public $items_with_ids; |
| 31 | |
| 32 | /** |
| 33 | * Constructor. |
| 34 | * Initializes the queue buffer. |
| 35 | * |
| 36 | * @access public |
| 37 | * |
| 38 | * @param int $id Sync queue buffer ID. |
| 39 | * @param array $items_with_ids Items for the buffer to work with. |
| 40 | */ |
| 41 | public function __construct( $id, $items_with_ids ) { |
| 42 | $this->id = $id; |
| 43 | $this->items_with_ids = $items_with_ids; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Retrieve the sync items in the buffer, in an ID => value form. |
| 48 | * |
| 49 | * @access public |
| 50 | * |
| 51 | * @return bool|array Sync items in the buffer. |
| 52 | */ |
| 53 | public function get_items() { |
| 54 | return array_combine( $this->get_item_ids(), $this->get_item_values() ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Retrieve the values of the sync items in the buffer. |
| 59 | * |
| 60 | * @access public |
| 61 | * |
| 62 | * @return array Sync items values. |
| 63 | */ |
| 64 | public function get_item_values() { |
| 65 | return Utils::get_item_values( $this->items_with_ids ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Retrieve the IDs of the sync items in the buffer. |
| 70 | * |
| 71 | * @access public |
| 72 | * |
| 73 | * @return array Sync items IDs. |
| 74 | */ |
| 75 | public function get_item_ids() { |
| 76 | return Utils::get_item_ids( $this->items_with_ids ); |
| 77 | } |
| 78 | } |
| 79 |