createWithSender( new Psr18XrpcRequestSender($this->httpClient), $defaultServiceUrl, $identityCacheTtl, $urlPolicy, ); } /** * Creates a client bound to an authenticated session. */ public function createAuthenticated( AuthenticatedSessionInterface $session, ?string $defaultServiceUrl = NULL, int|\DateInterval|null $identityCacheTtl = NULL, ?OutboundUrlPolicyInterface $urlPolicy = NULL, ): AtprotoClient { $serviceUrl = $defaultServiceUrl ?? $session->getPdsUrl(); return $this->createWithSender( new AuthenticatedXrpcRequestSender(new Psr18XrpcRequestSender($this->httpClient), $session, $serviceUrl), $serviceUrl, $identityCacheTtl, $urlPolicy, ); } /** * Creates a DID resolver with the factory dependencies. */ public function createDidResolver( int|\DateInterval|null $identityCacheTtl = NULL, ?OutboundUrlPolicyInterface $urlPolicy = NULL, string $cacheKeyPrefix = 'atproto.did_document', ): DidResolver { $identityCacheTtl ??= $this->identityCacheTtl; return new DidResolver( $this->httpClient, $this->requestFactory, $this->cache, $identityCacheTtl, $urlPolicy ?? $this->urlPolicy, cacheKeyPrefix: $cacheKeyPrefix, ); } /** * Creates a handle resolver with the factory dependencies. */ public function createHandleResolver( int|\DateInterval|null $identityCacheTtl = NULL, ?OutboundUrlPolicyInterface $urlPolicy = NULL, string $cacheKeyPrefix = 'atproto.handle_did', ): HandleResolver { $identityCacheTtl ??= $this->identityCacheTtl; return new HandleResolver( $this->httpClient, $this->requestFactory, $this->dnsTxtResolver, cache: $this->cache, cacheTtl: $identityCacheTtl, urlPolicy: $urlPolicy ?? $this->urlPolicy, cacheKeyPrefix: $cacheKeyPrefix, ); } /** * Creates an authoritative Lexicon repository. */ public function createLexiconRepository( int|\DateInterval|null $cacheTtl = 86_400, ?OutboundUrlPolicyInterface $urlPolicy = NULL, ): AuthoritativeLexiconRepository { $policy = $urlPolicy ?? $this->urlPolicy; return new AuthoritativeLexiconRepository( $this->dnsTxtResolver, $this->createDidResolver($cacheTtl, $policy, 'atproto.lexicon_publisher_did'), new XrpcClient( new Psr18XrpcRequestSender($this->httpClient), $this->requestFactory, $this->streamFactory, urlPolicy: $policy, ), $this->cache, $cacheTtl, ); } private function createWithSender( XrpcRequestSenderInterface $requestSender, ?string $defaultServiceUrl = NULL, int|\DateInterval|null $identityCacheTtl = NULL, ?OutboundUrlPolicyInterface $urlPolicy = NULL, ): AtprotoClient { $identityCacheTtl ??= $this->identityCacheTtl; $xrpc = new XrpcClient( $requestSender, $this->requestFactory, $this->streamFactory, $defaultServiceUrl, $urlPolicy ?? $this->urlPolicy, ); return new AtprotoClient( $xrpc, $this->createHandleResolver($identityCacheTtl, $urlPolicy), $this->createDidResolver($identityCacheTtl, $urlPolicy), ); } }