public function collectionProvider() { $data = [1, 2, 3, 4]; $queue = new Queue(); $queue->push(1); $stack = new Stack(); $stack->push(1); return [[new Vector($data), '[1,2,3,4]'], [new Set($data), '[1,2,3,4]'], [new Map(['test' => 'test']), '{"test": "test"}'], [$queue, '[1]'], [$stack, '[1]']]; }
public static function fromArray(array $arr) { $collection = new Queue(); foreach ($arr as $v) { if (is_array($v)) { $collection->enqueue(static::fromArray($v)); } else { $collection->enqueue($v); } } return $collection; }
/** * {@inheritDoc} */ public function execute($command) { $this->queue->enqueue($command); if (!$this->isDispatching) { $this->isDispatching = true; try { while (!$this->queue->isEmpty()) { $this->processCommand($this->queue->pop()); } } finally { $this->isDispatching = false; } } }
/** * {@inheritDoc} */ public function publish(DomainEventInterface $event) { $this->queue->enqueue($event); if (!$this->isPublishing && !$this->queue->isEmpty()) { $this->isPublishing = true; try { while (!$this->queue->isEmpty()) { $this->processEvent($this->queue->pop()); } } finally { $this->isPublishing = false; } } }
public function testEnqueueAndDequeueToArray() { $this->coll->enqueue('testing1'); $this->coll->enqueue('testing2'); $this->coll->enqueue('testing3'); $this->coll->dequeue(); $this->assertEquals(array('testing2', 'testing3'), $this->coll->toArray()); }