Files
api/services/nginx/app/interfaces/motorapi_i.php
T
Jeppe Bundgaard 7a852f5b54 Add nullable return types and improve exception handling in MotorAPI
- Updated `getCachedResult` methods across `motorapi`, `motorapi_i`, and `motorapi_lookups_o` to return `?object` for nullable results.
- Enhanced error handling in `xlvask_parser_stor_bil` by wrapping `getLicensePlateInformation` in a try-catch block to handle API exceptions gracefully.
- Introduced `cleanJSON` method in `motorapi` to sanitize and validate JSON data, ensuring robust parsing of cached responses.
- Optimized `getCachedResult` logic to handle null and invalid JSON scenarios with detailed error reporting.
2025-08-31 13:33:10 +02:00

122 lines
4.7 KiB
PHP

<?php
namespace interfaces;
use Exception;
interface motorapi_i
{
/**
* Get license plate information from the motorapi
* @param string $licensePlate The license plate to get information about (e.g. "AB12345")
* @param bool $ignoreCache Whether to ignore the cache or not. If true, the cache will be ignored and the request will be sent to the motorapi directly.
* @return object The license plate information
*/
function getLicensePlateInformation(string $licensePlate, bool $ignoreCache = true): object;
/**
* Get the daily request counter
* @return int The daily request counter
*/
function getDailyRequestCounter(): int;
/**
* Send a request to the motorapi
* @param string $licensePlate The license plate to get information about (e.g. "AB12345")
* @param string $endpoint The endpoint to send the request to (e.g. "vehicle")
* @param array $data The data to send with the request (e.g. ["key" => "value"])
* @param string $method The method to use for the request (e.g. "GET")
* @return object The response from the motorapi
*/
function sendRequest(string $licensePlate, string $endpoint, array $data, string $method): object;
/**
* Require the module to be enabled
* @return void
* @throws Exception If the module is not enabled
*/
function requireModuleEnabled(): void;
/**
* Require the license plate to be valid
* @param string $licensePlate The license plate to validate
* @return void
* @throws Exception If the license plate is not valid
*/
function requireValidLicensePlate(string $licensePlate): void;
/**
* Require the daily limit to not be exceeded
* @return void
* @throws Exception If the daily limit is exceeded
*/
function requireDailyLimitNotExceeded(): void;
/**
* Require the secret key to be valid
* @return void
* @throws Exception If the secret key is not valid
*/
function requireValidSecretKey(): void;
/**
* Send a GET request to the motorapi
* @param string $licensePlate The license plate to get information about
* @param string $endpoint The endpoint to send the request to
* @param array $data The data to send with the request
* @return object The response from the motorapi
*/
function sendGetRequest(string $licensePlate, string $endpoint, array $data): object;
/**
* Send a POST request to the motorapi
* @param string $licensePlate The license plate to get information about
* @param string $endpoint The endpoint to send the request to
* @param array $data The data to send with the request
* @return object The response from the motorapi
*/
function sendPostRequest(string $licensePlate, string $endpoint, array $data): object;
/**
* Send a PUT request to the motorapi
* @param string $licensePlate The license plate to get information about
* @param string $endpoint The endpoint to send the request to
* @param array $data The data to send with the request
* @return object The response from the motorapi
*/
function sendPutRequest(string $licensePlate, string $endpoint, array $data): object;
/**
* Send a DELETE request to the motorapi
* @param string $licensePlate The license plate to get information about
* @param string $endpoint The endpoint to send the request to
* @param array $data The data to send with the request
* @return object The response from the motorapi
*/
function sendDeleteRequest(string $licensePlate, string $endpoint, array $data): object;
/**
* Add a request to the log
* @param string $licensePlate The license plate to get information about
* @param string $endpoint The endpoint to send the request to
* @param object $response The response from the motorapi
* @return void
*/
function addRequestToLog(string $licensePlate, string $endpoint, object $response): void;
/**
* Check if a license plate response is stored in the log/local database/cache
* @param string $licensePlate The license plate to check
* @return bool Whether the license plate response is stored in the log/local database/cache
* @throws Exception If the license plate is not valid
*/
function isCached(string $licensePlate): bool;
/**
* Get the cached response for a license plate
* @param string $licensePlate The license plate to get the cached response for
* @return object|null The (latest) cached response for the license plate
* @throws Exception If the license plate is not valid or the response is not cached
*/
function getCachedResult(string $licensePlate): ?object;
}