private function getResourceDataV1(Resource $resource, Source $source)
 {
     if ($source->getUrl()) {
         $url = $source->getUrl();
     } else {
         $providerApiUrl = $resource->getPropertyValue('provider_apiurl');
         if (!$providerApiUrl) {
             throw new RuntimeException("No v1 provider_apiurl to get resource data");
         }
         $bsn = $resource->getPropertyValue('client_bsn');
         $ref = $resource->getPropertyValue('reference');
         switch ($resource->getType()) {
             case 'perinatologie/dossier':
                 $url = $providerApiUrl . '/' . $bsn . '/' . rawurlencode($ref);
                 break;
             default:
                 throw new RuntimeException("Unsupported resource type: " . $resource->getType());
         }
     }
     try {
         $hashSource = $url . $this->password;
         $headers = array();
         //echo "REQUESTING PROVIDER URL: " . $url . "\n";
         if ($this->username || $this->password) {
             // stripping http(s) because of load-balancer. Hub sees http only
             $securityHash = sha1(str_replace('https', 'http', $hashSource));
             $headers = ['uuid' => $this->username, 'securityhash' => $securityHash];
         }
         //echo "REQUESTING: " . $fullUrl . "\n";
         $res = $this->httpClient->get($url, ['headers' => $headers, 'verify' => $this->verify]);
         if ($res->getStatusCode() == 200) {
             $res = (string) $res->getBody();
             return $res;
         }
     } catch (\GuzzleHttp\Exception\RequestException $e) {
         ErrorResponseHandler::handle($e->getResponse());
     }
 }
Exemplo n.º 2
0
 private function buildRegisterXml(Resource $resource)
 {
     $resourceNode = new SimpleXMLElement('<resource type="' . $resource->getType() . '" />');
     foreach ($resource->getProperties() as $property) {
         $resourceNode->addChild('property', $property->getValue())->addAttribute('name', $property->getName());
     }
     foreach ($resource->getShares() as $share) {
         $shareNode = $resourceNode->addChild('share');
         $shareNode->addChild('name', $share->getName());
         $shareNode->addChild('identifier', $share->getIdentifier())->addAttribute('type', $share->getIdentifierType());
         $shareNode->addChild('permission', $share->getPermission());
     }
     //echo $clientNode->asXML();
     $dom = dom_import_simplexml($resourceNode)->ownerDocument;
     $dom->formatOutput = true;
     return $dom->saveXML();
 }