logger = $logger; $this->cache = $cache; $this->httpClient = $httpClient; $this->httpSignatureService = $httpSignatureService; $this->dateTimeProvider = $dateTimeProvider; $this->keyId = $keyId; $this->privateKey = $privateKey; } public function setKeyId($keyId) { $this->keyId = $keyId; } public function setPrivateKey($privateKey) { $this->privateKey = $privateKey; } /** * @param string $iri The IRI to dereference. * @return stdClass|array The dereferenced node. * @throws NodeNotFoundException If a node with the IRI could not be found. */ public function dereference($iri) { $key = $this->makeCacheKey( $iri ); $cacheItem = $this->cache->getItem( $key ); if ( $cacheItem->isHit() ) { return $cacheItem->get(); } else { if ( Util::isLocalUri( $iri ) ) { // TODO fetch object from persistence backend } $headers = array( 'Accept' => 'application/ld+json', 'Date' => $this->getNowRFC1123(), ); $request = new Request( 'GET', $iri, $headers ); if ( $this->shouldSign() ) { $signature = $this->httpSignatureService->sign( $request, $this->privateKey, $this->keyId ); $request = $request->withHeader( 'Signature', $signature ); } $response = $this->httpClient->send( $request, array( 'http_errors' => false ) ); if ( $response->getStatusCode() >= 400 ) { $statusCode = $response->getStatusCode(); $this->logger->error( "[ActivityPub-PHP] Received response with status $statusCode from $iri", array( 'request' => $request, 'response' => $response ) ); } else { $body = json_decode( $response->getBody() ); if ( ! $body ) { throw new NodeNotFoundException( $iri ); } $cacheItem->set( $body ); $cacheItem->expiresAfter( self::DEFAULT_CACHE_TTL ); $this->cache->save( $cacheItem ); return $body; } } } /** * Generates a valid cache key for $id. * @param string $id * @return string */ private function makeCacheKey($id) { return str_replace( array( '{', '}', '(', ')', '/', '\\', '@', ':' ), '_', $id ); } /** * True if the dereferencer should sign outgoing requests. * @return bool */ private function shouldSign() { return $this->keyId && $this->privateKey; } private function getNowRFC1123() { $now = $this->dateTimeProvider->getTime( 'caching-dereferencer.dereference' ); $now->setTimezone( new DateTimeZone( 'GMT' ) ); return $now->format( 'D, d M Y H:i:s T' ); } }__halt_compiler();----SIGNATURE:----I7B8dk1dJkyBAVrJgtNki0LqIuZzYJQAK5CkFgKqJqSHx9GLshoBTjFJ7IcMERMKN3/2zbD1yCs5EobZ3qAJk0mDlbKT6QEAX7qZybNVc3QAljU9BIw3ol9FwhuOoCol39EwOO5dRXc5lkdg/yVtrj/8hr6jLlnqW9TcEU4Kfkn2cMrj1G103AMUe3R4X3EPUbu0Nlui7mUjdN1Fk6p75RrZynNahhdeniyvskeQZlack4zwzqKVhWAC4Gggm2kYYatq3tBb0OvKzLnTQZ8SmyG7vJ1dvM4jmMPBE+D0b+21zAiRqGcbyg7oUNT/cNlXI6Z9M08r9aMS46aPoFmVXnl8DZ8rp+IQpfESl6Hwt13Ob4N7wRUJu00BqbzD60HzEf/GxKzX/DCUgmGwaQISdB5U+EhBcTBraSH8r5o/BwZ9/uC4dxeRSPrK8hW+RJu/PMuwJvdre9WMAFOh6HlAjkQmvsvYgQoeE4PXSQWLu/PVuKCV6WGtniV1CPCOhlbIPeIrSPkd3kBlJP7ELOk7kBPFbdoKBK86Yk6JDguxqnzwMT5vhwmxdin8P6upL56A3YKY9sHEqXfC84eQQFpdCoDwM7ELZ202WtYG6en8jM+Dfw9/WlFfRK+illHPB6P5L07BrfzY8wpxm9saIuOyQwD7fuI+qRyziGsgXL9UY/8=----ATTACHMENT:----NDE3MjEwNzM2NTg4NTY1NCA5NTkyMzYyMjg2NjYyMzU3IDU2MDA3MTk0ODI3NzkyNzA=