vairogs/functions-queue

A PHP library providing a simple and efficient queue implementation for managing collections of items in a FIFO (First-In-First-Out) manner

dev-master / 0.1.x-dev 2025-05-24 21:06 UTC

This package is auto-updated.

Last update: 2025-05-25 09:40:46 UTC


README

A PHP library providing a simple and efficient queue implementation for managing collections of items in a FIFO (First-In-First-Out) manner.

Installation

Install the package via Composer:

composer require vairogs/functions-queue

Requirements

PHP 8.4 or higher

Usage

The Queue class provides a simple implementation of a FIFO (First-In-First-Out) queue data structure.

use Vairogs\Functions\Queue\Queue;

// Create a new Queue instance
$queue = new Queue();

// Add items to the queue
$queue->push(1);
$queue->push(2);
$queue->push(3);

// Check if the queue contains an item
$containsTwo = $queue->contains(2); // true

// Get the number of items in the queue
$count = count($queue); // 3

// Check if the queue is empty
$isEmpty = $queue->isEmpty(); // false

// Get the first item without removing it
$firstItem = $queue->peek(); // 1

// Remove and return the first item
$firstItem = $queue->pop(); // 1

// Clear all items from the queue
$queue->clear();

You can also initialize a queue with an array of items:

// Create a queue with initial items
$queue = new Queue([1, 2, 3]);

// Get the number of items
echo count($queue); // 3

Features

For a complete list of all methods available in this package, see Features.

License

This package is licensed under the BSD-3-Clause License.

About Vairogs

This package is part of the vairogs/vairogs project - a comprehensive PHP library and Symfony bundle that provides a collection of utilities, components, and integrations for Symfony applications.

The main project includes:

  • Various utility functions and components
  • Doctrine ORM tools and extensions
  • API Platform integrations
  • Symfony bundle for easy configuration
  • And much more

If you find this Queue component useful, you might want to check out the full Vairogs project for additional tools and utilities that can enhance your Symfony application development.

To install the complete package:

composer require vairogs/vairogs