|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright 2025 SURFnet B.V. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +namespace OpenConext\EngineBlockBundle\Sbs; |
| 20 | + |
| 21 | +use OpenConext\EngineBlock\Http\HttpClient; |
| 22 | +use OpenConext\EngineBlockBundle\Pdp\Dto\Request; |
| 23 | +use OpenConext\EngineBlockBundle\Pdp\Dto\Response; |
| 24 | +use OpenConext\EngineBlockBundle\Pdp\PdpClientInterface; |
| 25 | +use OpenConext\EngineBlockBundle\Pdp\PolicyDecision; |
| 26 | + |
| 27 | +final class SbsClient implements PdpClientInterface |
| 28 | +{ |
| 29 | + /** |
| 30 | + * @var HttpClient |
| 31 | + */ |
| 32 | + private $httpClient; |
| 33 | + /** |
| 34 | + * @var string |
| 35 | + */ |
| 36 | + private $interruptLocation; |
| 37 | + /** |
| 38 | + * @var string |
| 39 | + */ |
| 40 | + private $entitlementsLocation; |
| 41 | + |
| 42 | + |
| 43 | + public function __construct( |
| 44 | + HttpClient $httpClient, |
| 45 | + string $interruptLocation, |
| 46 | + string $entitlementsLocation |
| 47 | + ) { |
| 48 | + $this->httpClient = $httpClient; |
| 49 | + $this->interruptLocation = $interruptLocation; |
| 50 | + $this->entitlementsLocation = $entitlementsLocation; |
| 51 | + } |
| 52 | + |
| 53 | + public function requestInterruptDecisionFor(Request $request) : PolicyDecision |
| 54 | + { |
| 55 | + $jsonData = $this->httpClient->post( |
| 56 | + json_encode($request), |
| 57 | + $this->interruptLocation, |
| 58 | + [], |
| 59 | + [ |
| 60 | + 'Content-Type' => 'application/json', |
| 61 | + 'Accept' => 'application/json', |
| 62 | + ] |
| 63 | + ); |
| 64 | + $response = Response::fromData($jsonData); |
| 65 | + |
| 66 | + return PolicyDecision::fromResponse($response); |
| 67 | + } |
| 68 | + public function requestEntitlementsFor(Request $request) : PolicyDecision |
| 69 | + { |
| 70 | + $jsonData = $this->httpClient->post( |
| 71 | + json_encode($request), |
| 72 | + $this->entitlementsLocation, |
| 73 | + [], |
| 74 | + [ |
| 75 | + 'Content-Type' => 'application/json', |
| 76 | + 'Accept' => 'application/json', |
| 77 | + ] |
| 78 | + ); |
| 79 | + $response = Response::fromData($jsonData); |
| 80 | + |
| 81 | + return PolicyDecision::fromResponse($response); |
| 82 | + } |
| 83 | +} |
0 commit comments