davide.cucurnia@vola.it
2024-02-08 d5d253a98cabfe8f57335a2805120335d5ab265d
commit | author | age
9f6455 1 <?php
DC 2
3 namespace App\Http\Controllers\FakeResponder;
4
5 use App\Http\Controllers\Controller;
24347e 6 use App\Http\Requests\genericPicasso;
9f6455 7 use App\Vola\Services\VolaFakeHTTPResponder\VolaFakeHTTPResponder;
DC 8 use Illuminate\Http\Request;
398fc7 9 use App\Vola\Classes\Utils;
9f6455 10
DC 11 class FakeResponder extends Controller
12 {
13
14     public array $headers;
15     public VolaFakeHTTPResponder $VolaFakeSSO;
16
17     function __construct()
18     {
19         $this->VolaFakeSSO = new VolaFakeHTTPResponder();
20         $this->headers = [
21             "Content-Type" => 'text/xml',
22         ];
cc9b73 23         if (config('custom.compressed_responses',false) === TRUE) {
D 24             $this->headers['content-encoding'] = 'gzip';
25         }
9f6455 26     }
DC 27
59b068 28     public function modelBasedRequest(Request $request)
91fb11 29     {
fcb093 30         \RequestLogger::logReceivedRequest($request);
91fb11 31
fcb093 32         $responseContent = $this->VolaFakeSSO->getModelBasedResponses($request);
D 33         $responseContent = $this->compressIfRequested($request, $responseContent);
91fb11 34
fcb093 35         return response($responseContent['data'], $responseContent['status'], $this->headers);
91fb11 36     }
D 37
9f6455 38     public function manageLegacyRequest(Request $request)
DC 39     {
fcb093 40         \RequestLogger::logReceivedRequest($request);
cc9b73 41
68b84d 42         $picassoRequest = (str_starts_with($request->getRequestUri(), '/picasso/',));
D 43         $profile = Utils::getRequestedUser($request);
44
45         if (isset($profile)) {
46             $responseContent = $this->VolaFakeSSO->getResponses($request, $profile, $picassoRequest);
fcb093 47             \RequestLogger::logProcessedRequest($request, $responseContent);
398fc7 48             $responseContent = $this->compressIfRequested($request, $responseContent);
9f6455 49             return response($responseContent, 200, $this->headers);
DC 50         } else {
fcb093 51             \RequestLogger::logRejectedRequest($request);
7c54fa 52             return response('No cookie, no logged', 400, $this->headers);
D 53         }
54     }
55
9f6455 56 }