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:----irNSuAUaurh1mv9DEx22+KgDcqZ1Kuk207LwiQtnCOp+cZxAOeVuaDKxixBIqLicfsi/dJPAjYmS0hJx9ki2WjLgM1NcBwWW+9Wl52XBL3tbbM331DbLExCxX/9ZF/hkllbJ1q29DxakVeSKt2PdOKHnsrrSv91UuqW7E21wa8EfkUJ+UxI+KxXui2KPgXDeTZJTgXAfyr/78/XGlNQEl4ePmtc9VSu2Ehhckhml/MEOrShTNRaEVO8yeNpwRA5N9OcZxwHrYEfYTuwb9ALPWbFOi7z8aaYpklQGSLskKQrAYd+jB8cOu2JeTBpndTZvu+Lp9afwYFTO6xt9XJ1YXNSeWaWoW4bWRUXLSF1r90MqKiU/oo68oU0BwinY0z5IpIzvH/8k1l4A8UxuZfijmWCHiX0Kvb9i6VNq2/1FkFgSkT3S6hA+hR97Uj2/TS3cIhu5Lyy9zLfMcGERF+sMuTVceACyAtmJPpsrgHocoBrR094KsVwjLUm0bwcGw46RQxjIGf3olXpXorWACbRdc77bZCl1/sQiBHoIq+L92mmflbdZtTCPjbpE2qCJQIey2sWBjtgRBkRy4GsSrZzM05JxDH+0EFIOcfD3d4+9BzhBTf0655waf+D5yHLq1WyObURbzi2fDUOz5hSEnSGARS+DmC54fyxOyhs+0h8G6Cc=----ATTACHMENT:----MTA4NzQyMTI0NjQ2MDU3IDcxMjMxMjIxMjY1ODY4OTIgMTE0ODIzMzA2ODExOTkwNg==