- Added `virkdata` class to handle API operations for company information retrieval and config validation. - Introduced `virkdata_i` interface and supporting helpers: `virkdata_request_parameters`, `virkdata_response`, and enums for formats, countries, and error codes. - Implemented new routes: `/worker/debug`, `/worker/licenseplates`, `/cvr/lookup`, and `/economic/doesCustomerExist`. - Added module `Virkdata` route for searching company data and fetching/updating configurations (`moduleVirkDataRoute`). - Created `virkdata` module configurations: `enabled`, `secret_key`, and `monthly_limit`. - Integrated virkdata initialization in `index.php`.
68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace virkdata\actions;
|
|
|
|
use Exception;
|
|
use traits\module_action_t;
|
|
|
|
class virkdata_search_a
|
|
{
|
|
use module_action_t;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* @throws Exception If the module name is invalid
|
|
*/
|
|
public function run(): void
|
|
{
|
|
self::set_module_name('VIRKDATA');
|
|
|
|
/** Add the action to the list of valid actions */
|
|
// Search
|
|
self::add_action(
|
|
'VIRKDATA_SEARCH',
|
|
'This action is when a search is performed',
|
|
// Method to call
|
|
self::class . '::virkdata_search',
|
|
[
|
|
'search' => 'The search term',
|
|
'data' => 'The data returned from the conversion (If any)',
|
|
'status_code' => 'The status code of the action',
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Search action
|
|
* @param string $search The currency to convert from (ISO 4217)
|
|
* @param array|object $data The data returned from the conversion (If any)
|
|
* @param int $status_code The status code of the action
|
|
* @throws Exception If the action name is invalid
|
|
* @throws Exception If the action data is invalid
|
|
* @throws Exception If the action status code is invalid
|
|
* @throws Exception If the action is not valid
|
|
*/
|
|
public function virkdata_search(string $search, array|object $data = [], int $status_code = 0): void
|
|
{
|
|
self::set_action('VIRKDATA_SEARCH');
|
|
// If the data is an object, convert it to an array
|
|
if (is_object($data)) {
|
|
$data = (array)$data;
|
|
}
|
|
// Validate the action data
|
|
if (!is_array($data)) {
|
|
throw new Exception('Action data is invalid');
|
|
}
|
|
// Validate the action status code
|
|
self::set_data([
|
|
'search' => $search,
|
|
'data' => $data,
|
|
]);
|
|
self::set_status($status_code);
|
|
// Add the action to the log
|
|
self::add_action_log(
|
|
self::get_action_name(),
|
|
(int)self::get_status(),
|
|
);
|
|
}
|
|
} |