Each custom application consists of a directory with at least one file: index.php. This file acts as the entry point and must return a PHP closure (an anonymous function). The SDK will automatically inject interfaces into this closure to give you access to JobRouter®’s internal functionality — such as user management or database access.
Example: Accessing User Data
Here’s a practical example of a simple application that uses the SDK to retrieve and display information about a specific user:
<?php
use Doctrine\DBAL\Exception;
use JobRouter\Common\Database\ResultInterface;
use JobRouter\Sdk\ConnectionManagerInterface;
use JobRouter\Sdk\UserManagerInterface;
return function (UserManagerInterface $userInterface, ConnectionManagerInterface $connectionManager): void {
echo '<h1 style="color: #fc0">JobRouter SDK user interface example!</h1>';
$userName = 'example_user';
try {
$userByName = $userInterface->getUserByUsername($userName);
echo '<h3 style="color: #f44;">User Fullname from Interface: ' . $userByName->getFullName() . '</h3>';
} catch (\JobRouterException) {
echo '<h3 style="color: #f44;">The user ' . $userName . ' does not exist!</h3>';
}
$jobDB = $connectionManager->getJobDB();
$result = $jobDB->query('SELECT lastname, prename FROM JRUSERS WHERE username = ' . $jobDB->quote($userName));
if ($result === false) {
echo '<h3 style="color: #f44;">ERROR!</h3>';
echo '<p style="color: #f44;">Message: ' . $jobDB->getErrorMessage() . '</p>';
} else {
if ($userFromDB = $jobDB->fetchRow($result)) {
echo '<h3 style="color: #f44;">User Fullname from Interface: ' . $userFromDB['prename'] . ' ' . $userFromDB['lastname'] . '</h3>';
} else {
echo '<h3 style="color: #f44;">The user ' . $userName . ' does not exist in database!</h3>';
}
}
};
What’s Happening Here?
•Closure Structure: The function returned from index.php receives two SDK interfaces:
oUserManagerInterface – for accessing user data
oConnectionManagerInterface – for querying the internal database
•User Lookup via SDK: The $userInterface->getUserByUsername() method queries the user directory and returns a user object if the user exists.
•Direct Database Access: The SDK also allows executing raw SQL queries using the ConnectionManagerInterface.
•Error Handling: Exceptions and errors are caught and displayed directly in the browser. For production use, a more robust error handling or logging strategy is recommended.
Understanding the Closure and Interface Injection
Each custom application must return a PHP closure — an anonymous function — from its index.php file. The SDK automatically injects the required interfaces into this function for you. These interfaces give you access to various core features of JobRouter®, such as the database, users, settings, and more.
You don’t have to create or initialize these interfaces yourself — just declare them as parameters in the function. The SDK takes care of the rest.
Here’s what you need to know:
•You can list any number of supported interfaces in the function's parameter list.
•The order of the parameters doesn't matter.
•You must include the appropriate use statements at the top of the file so PHP knows what each interface refers to.
Tip: Think of it like ordering tools for a task — you just list what you need, and the SDK hands them to you, ready to use.
For all available interfaces please see the Interfaces section.
Output Example
If the user exists, you’ll see:
Otherwise you will get: