apiKey ?? self::envOrNull('OPENSTATUS_API_KEY'); $baseUrl = $options->baseUrl ?? self::envOrNull('OPENSTATUS_API_URL') ?? self::DEFAULT_BASE_URL; $defaultFactory = new HttpFactory(); $requestFactory = $options->requestFactory ?? $defaultFactory; $streamFactory = $options->streamFactory ?? $defaultFactory; $http = $options->httpClient ?? new GuzzleClient(['timeout' => $options->timeout]); $defaultHeaders = [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'User-Agent' => sprintf('openstatus-php/%s php/%s', self::VERSION, PHP_VERSION), ]; if ($apiKey !== null) { $defaultHeaders['x-openstatus-key'] = $apiKey; } $transport = new JsonTransport( http: $http, requestFactory: $requestFactory, streamFactory: $streamFactory, baseUrl: $baseUrl, defaultHeaders: $defaultHeaders, logger: $options->logger, ); $this->health = new Health(new HealthV1(new HealthServiceClient($transport))); $this->monitor = new Monitor(new MonitorV1(new MonitorServiceClient($transport))); $this->statusReport = new StatusReport(new StatusReportV1(new StatusReportServiceClient($transport))); $this->statusPage = new StatusPage(new StatusPageV1(new StatusPageServiceClient($transport))); $this->maintenance = new Maintenance(new MaintenanceV1(new MaintenanceServiceClient($transport))); $this->notification = new Notification(new NotificationV1(new NotificationServiceClient($transport))); } private static function envOrNull(string $name): ?string { $value = getenv($name); return $value === false || $value === '' ? null : $value; } }