Skip to content

ConnectionManagerInterface

Alexander Saal edited this page Aug 4, 2025 · 1 revision

ConnectionManagerInterface

Interface & Methods

interface ConnectionManagerInterface
{
    /**
     * Return the default JobRouter Database Connection.
     *
     * @return \JobRouter\Sdk\JobDBInterface JobDB Interface
     */
    public function getJobDB(): \JobRouter\Sdk\JobDBInterface;

    /**
     * Return a JobRouter Database Connection by its name.
     *
     * @param string $connectionName Connection name
     *
     * @return \JobRouter\Sdk\JobDBInterface JobDB Interface
     *
     * @throws \Doctrine\DBAL\Exception
     * @throws \JobRouterException
     */
    public function getDBConnection(string $connectionName): \JobRouter\Sdk\JobDBInterface;
}

Example

<?php

use Doctrine\DBAL\Exception;
use JobRouter\Common\Database\ResultInterface;
use JobRouter\Sdk\ConnectionManagerInterface;

return function (ConnectionManagerInterface $connectionManager): void {
    echo '<h1 style="color: #fc0">SDK database example!</h1>';

    echo '<h3 style="color: #fc0;">JobRouter Users (internal connection) - getJobDB()</h3>';
    try {
        $jobDB = $connectionManager->getJobDB();

        // Do something with the $jobDB
    } catch (\JobRouterException|Exception $e) {
        echo '<h3 style="color: #f44;">ERROR!</h3>';
        echo '<p style="color: #f44;">Message: ' . $e->getMessage() .  '</p>';
    }

    echo '<h3 style="color: #59aa6e;">JobRouter (Global connection) - getDBConnection(\'GC_JOBDATA\')</h3>';
    try {
        $gcJobData = $connectionManager->getDBConnection('GC_JOBDATA');

        // Do something with the $gcJobData
    } catch (\JobRouterException|Exception $e) {
        echo '<h3 style="color: #f44;">ERROR!</h3>';
        echo '<p style="color: #f44;">Message: ' . $e->getMessage() .  '</p>';
    }

    echo '<h3 style="color: #59aa6e;">JobRouter (Global connection) - getDBConnection(\'GlobalConnectionDoesNotExists\')</h3>';
    try {
        $connectionManager->getDBConnection('GlobalConnectionDoesNotExists');
    } catch (\JobRouterException|\Exception $e) {
        echo '<h3 style="color: #f44;">ERROR!</h3>';
        echo '<p style="color: #f44;">Message: ' . $e->getMessage() .  '</p>';
    }
};
Clone this wiki locally