0 follower

Final Class Yiisoft\Queue\Stubs\InMemoryAdapter

InheritanceYiisoft\Queue\Stubs\InMemoryAdapter
ImplementsYiisoft\Queue\Adapter\AdapterInterface

In-memory implementation of {@see AdapterInterface} for testing and development purposes.

This adapter stores messages in a local array and processes them sequentially within the same process without any external queue backend. Messages are assigned incremental integer identifiers and are handled in FIFO order.

Note: This implementation is not persistent and should not be used in production, as all data is lost when the process ends.

Method Details

Hide inherited methods

getMessagesList() public method

public Yiisoft\Queue\Message\MessageInterface[] getMessagesList ( )

                public function getMessagesList(): array
{
    return array_values($this->messages);
}

            
push() public method

public Yiisoft\Queue\Message\MessageInterface push ( Yiisoft\Queue\Message\MessageInterface $message )
$message Yiisoft\Queue\Message\MessageInterface

                public function push(MessageInterface $message): MessageInterface
{
    $id = count($this->messages) + $this->current;
    $this->messages[] = $message;
    return new IdEnvelope($message, $id);
}

            
runExisting() public method

public void runExisting ( callable $handlerCallback )
$handlerCallback callable

                public function runExisting(callable $handlerCallback): void
{
    $result = true;
    while (isset($this->messages[$this->current]) && $result === true) {
        $result = $handlerCallback($this->messages[$this->current]);
        unset($this->messages[$this->current]);
        $this->current++;
    }
}

            
status() public method

public \Yiisoft\Queue\MessageStatus status ( integer|string $id )
$id integer|string

                public function status(int|string $id): MessageStatus
{
    $id = (int) $id;
    if ($id < 0) {
        return MessageStatus::NOT_FOUND;
    }
    if ($id < $this->current) {
        return MessageStatus::DONE;
    }
    if (isset($this->messages[$id])) {
        return MessageStatus::WAITING;
    }
    return MessageStatus::NOT_FOUND;
}

            
subscribe() public method

public void subscribe ( callable $handlerCallback )
$handlerCallback callable

                public function subscribe(callable $handlerCallback): void
{
    $this->runExisting($handlerCallback);
}