Compare commits
8
Commits
9c5e089573
...
ad6fa5ef2a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad6fa5ef2a | ||
|
|
6e3665696c | ||
|
|
99a4f2787b | ||
|
|
5ae01c3038 | ||
|
|
90851908b7 | ||
|
|
8c61b69320 | ||
|
|
48c120ab01 | ||
|
|
ea8fbaebfe |
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "yourorg/api",
|
||||
"name": "elixforms-web-services/api",
|
||||
"require": {
|
||||
"php": ">=7.4",
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
|
||||
@@ -41,7 +41,7 @@ class ElixFormsController
|
||||
$username = $this->config->secret('elixforms_api_username');
|
||||
$password = $this->config->secret('elixforms_api_password');
|
||||
|
||||
if (!is_string($username) || trim($username) === '' || !is_string($password) || $password === '') {
|
||||
if (!\is_string($username) || trim($username) === '' || !\is_string($password) || $password === '') {
|
||||
throw new ElixFormsException('Credenziali elixForms non configurate.');
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class ElixFormsController
|
||||
$matchingInstances = [];
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
if (!is_array($instance)) {
|
||||
if (!\is_array($instance)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -67,18 +67,16 @@ class ElixFormsController
|
||||
$exportGroup
|
||||
);
|
||||
|
||||
foreach ($exportTags as $exportTag) {
|
||||
if (!is_array($exportTag) || !isset($exportTag['name'])) {
|
||||
continue;
|
||||
}
|
||||
$exportTagsByName = array_column($exportTags, null, 'name');
|
||||
if (!\array_key_exists($fieldName, $exportTagsByName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = (string) $exportTag['name'];
|
||||
$value = isset($exportTag['value']) ? (string) $exportTag['value'] : '';
|
||||
$exportTag = $exportTagsByName[$fieldName];
|
||||
$value = isset($exportTag['value']) ? (string) $exportTag['value'] : '';
|
||||
|
||||
if (strcasecmp($name, $fieldName) === 0 && stripos($value, $fieldValue) !== false) {
|
||||
$matchingInstances[] = $instance;
|
||||
break;
|
||||
}
|
||||
if (stripos($value, $fieldValue) !== false) {
|
||||
$matchingInstances[] = $instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +85,7 @@ class ElixFormsController
|
||||
|
||||
private function requiredString(array $values, string $key): ?string
|
||||
{
|
||||
if (!isset($values[$key]) || !is_string($values[$key])) {
|
||||
if (!isset($values[$key]) || !\is_string($values[$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -98,11 +96,11 @@ class ElixFormsController
|
||||
|
||||
private function optionalNonEmptyString(array $values, string $key, string $default): ?string
|
||||
{
|
||||
if (!array_key_exists($key, $values)) {
|
||||
if (!\array_key_exists($key, $values)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (!is_string($values[$key])) {
|
||||
if (!\is_string($values[$key])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -114,7 +112,7 @@ class ElixFormsController
|
||||
private function requestId(array $instance)
|
||||
{
|
||||
foreach (['idDomanda', 'requestId', 'idRequest'] as $key) {
|
||||
if (isset($instance[$key]) && (is_int($instance[$key]) || is_string($instance[$key]))) {
|
||||
if (isset($instance[$key]) && (\is_int($instance[$key]) || \is_string($instance[$key]))) {
|
||||
return $instance[$key];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class Container {
|
||||
*/
|
||||
public function make(string $abstract) {
|
||||
// return existing singleton instance if already created
|
||||
if (array_key_exists($abstract, $this->instances) && $this->instances[$abstract] !== null) {
|
||||
if (\array_key_exists($abstract, $this->instances) && $this->instances[$abstract] !== null) {
|
||||
return $this->instances[$abstract];
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class Container {
|
||||
if (is_callable($concrete)) {
|
||||
// factory receives the container
|
||||
$object = $concrete($this);
|
||||
} elseif (is_string($concrete) && class_exists($concrete)) {
|
||||
} elseif (\is_string($concrete) && class_exists($concrete)) {
|
||||
$object = $this->build($concrete);
|
||||
} else {
|
||||
throw new \Exception("Invalid binding for [{$abstract}]");
|
||||
@@ -78,7 +78,7 @@ class Container {
|
||||
}
|
||||
|
||||
// if abstract was registered as singleton, cache the instance
|
||||
if (array_key_exists($abstract, $this->instances)) {
|
||||
if (\array_key_exists($abstract, $this->instances)) {
|
||||
$this->instances[$abstract] = $object;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class Json
|
||||
public static function sendError($message = 'Bad Request', int $status = 400, ?LoggerInterface $logger = null): void
|
||||
{
|
||||
$payload = [
|
||||
'error' => is_array($message) ? $message : ['message' => $message]
|
||||
'error' => \is_array($message) ? $message : ['message' => $message]
|
||||
];
|
||||
|
||||
if ($logger) {
|
||||
|
||||
@@ -36,11 +36,11 @@ class ElixFormsApiClient
|
||||
}
|
||||
$queryParts[] = 'moduleTag=' . rawurlencode($moduleTag);
|
||||
|
||||
$url = $this->baseUrl . '/eF/api/request/lookup/by-status?' . implode('&', $queryParts);
|
||||
$payload = $this->getJson($url, $authToken, $username, 'LookupByStatus');
|
||||
$url = "{$this->baseUrl}/api/request/lookup/by-status?" . implode('&', $queryParts);
|
||||
$payload = $this->getJsonAsArray($url, $authToken, $username, 'LookupByStatus');
|
||||
$requests = $payload['value']['requests'] ?? [];
|
||||
|
||||
if (!is_array($requests)) {
|
||||
if (!\is_array($requests)) {
|
||||
throw new ElixFormsException('Risposta LookupByStatus non valida: requests deve essere un array.');
|
||||
}
|
||||
|
||||
@@ -64,31 +64,31 @@ class ElixFormsApiClient
|
||||
throw new \InvalidArgumentException('exportGroup deve essere una stringa non vuota.');
|
||||
}
|
||||
|
||||
$url = sprintf(
|
||||
'%s/eF/services/api/request/%s/view/_DEFAULT/exportTags/get/v1?moduleTag=%s&exportGroup=%s',
|
||||
$url = \sprintf(
|
||||
'%s/services/api/request/%s/view/_DEFAULT/exportTags/get/v1?moduleTag=%s&exportGroup=%s',
|
||||
$this->baseUrl,
|
||||
rawurlencode((string) $requestId),
|
||||
rawurlencode($moduleTag),
|
||||
rawurlencode($exportGroup)
|
||||
);
|
||||
$payload = $this->getJson($url, $authToken, $username, 'GetExportTags');
|
||||
$payload = $this->getJsonAsArray($url, $authToken, $username, 'GetExportTags');
|
||||
$exportTags = $payload['value']['exportTags'] ?? [];
|
||||
|
||||
if (!is_array($exportTags)) {
|
||||
if (!\is_array($exportTags)) {
|
||||
throw new ElixFormsException('Risposta GetExportTags non valida: exportTags deve essere un array.');
|
||||
}
|
||||
|
||||
return array_values($exportTags);
|
||||
}
|
||||
|
||||
private function getJson(
|
||||
private function getJsonAsArray(
|
||||
string $url,
|
||||
string $authToken,
|
||||
string $username,
|
||||
string $operation
|
||||
): array {
|
||||
$response = $this->httpClient->get($url, [
|
||||
'Authorization' => 'Bearer ' . $authToken,
|
||||
'Authorization' => "Bearer {$authToken}",
|
||||
'Accept' => 'application/json',
|
||||
'x-requested-with' => 'XMLHttpRequest',
|
||||
'x-api-username' => $username,
|
||||
@@ -96,7 +96,7 @@ class ElixFormsApiClient
|
||||
|
||||
$status = $response['status'] ?? 500;
|
||||
if ($status !== 200) {
|
||||
throw new ElixFormsException(sprintf(
|
||||
throw new ElixFormsException(\sprintf(
|
||||
'Errore durante %s. HTTP Status: %d',
|
||||
$operation,
|
||||
$status
|
||||
@@ -105,13 +105,13 @@ class ElixFormsApiClient
|
||||
|
||||
$payload = $response['json'] ?? null;
|
||||
$jsonError = JSON_ERROR_NONE;
|
||||
if (!is_array($payload) && isset($response['body']) && is_string($response['body'])) {
|
||||
if (!\is_array($payload) && isset($response['body']) && \is_string($response['body'])) {
|
||||
$payload = json_decode($response['body'], true);
|
||||
$jsonError = json_last_error();
|
||||
}
|
||||
|
||||
if (!is_array($payload) || $jsonError !== JSON_ERROR_NONE) {
|
||||
throw new ElixFormsException(sprintf(
|
||||
if (!\is_array($payload) || $jsonError !== JSON_ERROR_NONE) {
|
||||
throw new ElixFormsException(\sprintf(
|
||||
'Risposta non valida da %s: atteso JSON.',
|
||||
$operation
|
||||
));
|
||||
@@ -120,7 +120,7 @@ class ElixFormsApiClient
|
||||
$globalStatus = $payload['value']['globalStatus'] ?? null;
|
||||
if ($globalStatus === 'ERROR') {
|
||||
$description = $payload['value']['description'] ?? 'errore non specificato';
|
||||
throw new ElixFormsException(sprintf(
|
||||
throw new ElixFormsException(\sprintf(
|
||||
'%s ha restituito un errore: %s',
|
||||
$operation,
|
||||
$description
|
||||
|
||||
@@ -23,11 +23,15 @@ class ElixFormsAuthenticationClient {
|
||||
* @throws ElixFormsException Se le credenziali sono errate o c'è un errore server
|
||||
*/
|
||||
public function login(string $username, string $password): string {
|
||||
$url = $this->baseUrl . '/eF/services/api/authentication/login/v1';
|
||||
$url = "{$this->baseUrl}/services/api/authentication/login/v1";
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->post($url, [
|
||||
'form_params' => [
|
||||
'headers' => [
|
||||
'x-requested-with' => 'XMLHttpRequest',
|
||||
'Content-Type' => 'application/json'
|
||||
],
|
||||
'json' => [
|
||||
'username' => $username,
|
||||
'password' => $password
|
||||
]
|
||||
@@ -64,12 +68,12 @@ class ElixFormsAuthenticationClient {
|
||||
* @throws ElixFormsException Se c'è un errore durante il logout
|
||||
*/
|
||||
public function logout(string $username, string $token): bool {
|
||||
$url = $this->baseUrl . '/eF/services/api/authentication/' . urlencode($username) . '/logout/v1';
|
||||
$url = "{$this->baseUrl}/services/api/authentication/" . urlencode($username) . '/logout/v1';
|
||||
|
||||
try {
|
||||
$response = $this->httpClient->post($url, [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Authorization' => "Bearer {$token}",
|
||||
'Content-Type' => 'application/x-www-form-urlencoded'
|
||||
]
|
||||
]);
|
||||
|
||||
@@ -54,16 +54,22 @@ final class ElixFormsControllerTest extends TestCase
|
||||
throw new \RuntimeException('exportGroup non inoltrato al client.');
|
||||
}
|
||||
|
||||
$values = [
|
||||
10 => 'Nessuna corrispondenza',
|
||||
20 => 'Il contratto ABC-123 è presente',
|
||||
30 => 'Altro valore',
|
||||
$tags = [
|
||||
10 => [
|
||||
'name' => 'contratto.altro',
|
||||
'value' => 'Il contratto ABC-123 è presente',
|
||||
],
|
||||
20 => [
|
||||
'name' => 'contratto.id',
|
||||
'value' => 'Il contratto ABC-123 è presente',
|
||||
],
|
||||
30 => [
|
||||
'name' => 'contratto.id',
|
||||
'value' => 'Altro valore',
|
||||
],
|
||||
];
|
||||
|
||||
return [[
|
||||
'name' => 'contratto.id',
|
||||
'value' => $values[$requestId],
|
||||
]];
|
||||
return [$tags[$requestId]];
|
||||
}
|
||||
};
|
||||
$config = new class extends Config {
|
||||
|
||||
Reference in New Issue
Block a user