Developer corner
Target group: Developers
Create own logic
You can use the TYPO3 JobRouter Connector as a starting point for your own
logic, for example, to synchronise JobData tables or retrieve archive documents.
Since this extension relies on the JobRouter REST Client library, you can get
a Rest
object to call the JobRouter® REST API.
Example
To simplify the creation of this client object, a factory method is available. Let's have a look at an example in the TYPO3 context:
EXT:my_extension/Classes/Controller/MyController.php
<?php
declare(strict_types=1);
use JobRouter\AddOn\RestClient\Exception\ExceptionInterface;
use JobRouter\AddOn\Typo3Connector\Domain\Entity\Connection;
use JobRouter\AddOn\Typo3Connector\Domain\Repository\ConnectionRepository;
use JobRouter\AddOn\Typo3Connector\Exception\ConnectionNotFoundException;
use JobRouter\AddOn\Typo3Connector\RestClient\RestClientFactory;
use Psr\Http\Message\ResponseInterface;
final class MyController
{
private ConnectionRepository $connectionRepository;
private RestClientFactory $restClientFactory;
public function __construct(
ConnectionRepository $connectionRepository,
RestClientFactory $restClientFactory,
) {
$this->connectionRepository = $connectionRepository;
$this->restClientFactory = $restClientFactory;
}
public function myAction(): ResponseInterface
{
try {
/** @var Connection $connection */
$connection = $this->connectionRepository->findByHandle('example');
} catch (ConnectionNotFoundException) {
// The connection is not found or disabled
}
try {
$client = $this->restClientFactory->create($connection, 60);
} catch (ExceptionInterface) {
// Maybe authentication failure or HTTP error
}
// Now you can call the request() method of the $client
}
}
Explanation:
- Line 29: Retrieve the
Connection
entity class with handleexample
, which holds the base URL of the JobRouter® installation and the credentials. Of course, the connection must be registered first in the Connections module. - Lines 30-32: It can be the case that there is no connection entity available:
There is no connection with handle
example
or the connection is disabled. So you have to consider this case. - Line 35: Create the REST client with the
create
method of the() Rest
. The first argument is theClient Factory Connection
model, the second argument the optional lifetime of the authentication token. With the call the authentication is done immediately, so an exception can be thrown if a HTTP error occurs or the authentication failed. With the client object you can make the calls to the REST API. Have a look at the JobRouter REST Client examples.
Note
Have a look at additional TYPO3 extensions for synchronising JobData tables or starting process instances from TYPO3.