primi 3 clienti // test_clienti_full.php?top=5 -> primi 5 clienti // test_clienti_full.php?id=123 -> solo il cliente con IdCliente = 123 // test_clienti_full.php?expand=XYZ -> include anche la relazione XYZ require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; require_once __DIR__ . '/class/VisualLimsApiClient.class.php'; header('Content-Type: application/json; charset=utf-8'); ini_set('display_errors', '0'); error_reporting(E_ALL); try { $api = VisualLimsApiClient::getInstance(); $top = isset($_GET['top']) ? max(1, min(20, (int) $_GET['top'])) : 3; $params = [ '$top' => $top, '$orderby' => 'Nominativo asc', ]; if (isset($_GET['id']) && ctype_digit($_GET['id'])) { $params['$filter'] = 'IdCliente eq ' . (int) $_GET['id']; } if (!empty($_GET['expand']) && preg_match('/^[A-Za-z0-9_,\/()$=;]+$/', $_GET['expand'])) { $params['$expand'] = $_GET['expand']; } // PHP_QUERY_RFC3986 codifica gli spazi come %20 (più compatibile con OData) $endpoint = 'Cliente?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986); $data = $api->get($endpoint); // Copia su file per consultarla con calma file_put_contents( __DIR__ . '/clienti_full_response.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ); // Elenco dei nomi dei campi trovati, utile per capire cosa è disponibile $campi = []; foreach ($data['value'] ?? [] as $row) { $campi = array_unique(array_merge($campi, array_keys($row))); } echo json_encode([ 'endpoint' => $endpoint, 'campi' => array_values($campi), 'dati' => $data, ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } catch (Throwable $e) { http_response_code(500); echo json_encode([ 'error' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); }