MemoryQueue.php 808 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Elgg\Queue;
  3. /**
  4. * FIFO queue that is memory based (not persistent)
  5. *
  6. * WARNING: API IN FLUX. DO NOT USE DIRECTLY.
  7. *
  8. * @access private
  9. *
  10. * @package Elgg.Core
  11. * @subpackage Queue
  12. * @since 1.9.0
  13. */
  14. class MemoryQueue implements \Elgg\Queue\Queue {
  15. /* @var array */
  16. protected $queue = array();
  17. /**
  18. * Create a queue
  19. */
  20. public function __construct() {
  21. $this->queue = array();
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function enqueue($item) {
  27. return (bool)array_push($this->queue, $item);
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function dequeue() {
  33. return array_shift($this->queue);
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function clear() {
  39. $this->queue = array();
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function size() {
  45. return count($this->queue);
  46. }
  47. }