master

laravel/framework

Last updated at: 29/12/2023 09:23

DatabaseConnector.php

TLDR

This file is a part of the Illuminate Queue package and contains the DatabaseConnector class. It is responsible for establishing a connection to a database queue.

Methods

connect

This method takes an array of configuration options and establishes a connection to a database queue using the provided configuration. It returns an instance of the DatabaseQueue class.

Classes

DatabaseConnector

This class is responsible for connecting to a database queue. It implements the ConnectorInterface interface. The DatabaseConnector class has the following attributes:

  • $connections: An instance of Illuminate\Database\ConnectionResolverInterface that holds all the database connections.

The class has the following methods:

  • __construct: A constructor method that takes an instance of Illuminate\Database\ConnectionResolverInterface and sets it to the $connections attribute.
  • connect: A method that takes an array of configuration options and establishes a connection to the database queue. It returns an instance of the DatabaseQueue class.
<?php

namespace Illuminate\Queue\Connectors;

use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Queue\DatabaseQueue;

class DatabaseConnector implements ConnectorInterface
{
    /**
     * Database connections.
     *
     * @var \Illuminate\Database\ConnectionResolverInterface
     */
    protected $connections;

    /**
     * Create a new connector instance.
     *
     * @param  \Illuminate\Database\ConnectionResolverInterface  $connections
     * @return void
     */
    public function __construct(ConnectionResolverInterface $connections)
    {
        $this->connections = $connections;
    }

    /**
     * Establish a queue connection.
     *
     * @param  array  $config
     * @return \Illuminate\Contracts\Queue\Queue
     */
    public function connect(array $config)
    {
        return new DatabaseQueue(
            $this->connections->connection($config['connection'] ?? null),
            $config['table'],
            $config['queue'],
            $config['retry_after'] ?? 60,
            $config['after_commit'] ?? null
        );
    }
}