| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . "/lib/BAD_REQUEST.php"; |
| 4 | require_once __DIR__ . "/lib/recibeJson.php"; |
| 5 | require_once __DIR__ . "/lib/ProblemDetailsException.php"; |
| 6 | |
| 7 | function recibeSuscripcion() |
| 8 | { |
| 9 | |
| 10 | $objeto = recibeJson(); |
| 11 | |
| 12 | if ( |
| 13 | !isset($objeto->authToken) |
| 14 | || !is_string($objeto->authToken) |
| 15 | || $objeto->authToken === "" |
| 16 | ) |
| 17 | throw new ProblemDetailsException([ |
| 18 | "status" => BAD_REQUEST, |
| 19 | "title" => "El authToken debe ser texto que no esté en blanco.", |
| 20 | "type" => "/errors/authtokenincorrecto.html", |
| 21 | ]); |
| 22 | |
| 23 | if ( |
| 24 | !isset($objeto->contentEncoding) |
| 25 | || !is_string($objeto->contentEncoding) |
| 26 | || $objeto->contentEncoding === "" |
| 27 | ) |
| 28 | throw new ProblemDetailsException([ |
| 29 | "status" => BAD_REQUEST, |
| 30 | "title" => "La contentEncoding debe ser texto que no esté en blanco.", |
| 31 | "type" => "/errors/contentencodingincorrecta.html", |
| 32 | ]); |
| 33 | |
| 34 | if ( |
| 35 | !isset($objeto->endpoint) |
| 36 | || !is_string($objeto->endpoint) |
| 37 | || $objeto->endpoint === "" |
| 38 | ) |
| 39 | throw new ProblemDetailsException([ |
| 40 | "status" => BAD_REQUEST, |
| 41 | "title" => "El endpoint debe ser texto que no esté en blanco.", |
| 42 | "type" => "/errors/endpointincorrecto.html", |
| 43 | ]); |
| 44 | |
| 45 | if ( |
| 46 | !isset($objeto->publicKey) |
| 47 | || !is_string($objeto->publicKey) |
| 48 | || $objeto->publicKey === "" |
| 49 | ) |
| 50 | throw new ProblemDetailsException([ |
| 51 | "status" => BAD_REQUEST, |
| 52 | "title" => "La publicKey debe ser texto que no esté en blanco.", |
| 53 | "type" => "/errors/publickeyincorrecta.html", |
| 54 | ]); |
| 55 | |
| 56 | return [ |
| 57 | "SUS_AUT_TOK" => $objeto->authToken, |
| 58 | "SUS_CONT_ENCOD" => $objeto->contentEncoding, |
| 59 | "SUS_ENDPOINT" => $objeto->endpoint, |
| 60 | "SUS_PUB_KEY" => $objeto->publicKey, |
| 61 | ]; |
| 62 | } |
| 63 | |