file = $file; if ($format === 'json' && is_null($subjectTokenFieldName)) { throw new InvalidArgumentException( 'subject_token_field_name must be set when format is JSON' ); } $this->format = $format; $this->subjectTokenFieldName = $subjectTokenFieldName; } public function fetchSubjectToken(callable $httpHandler = null): string { $contents = file_get_contents($this->file); if ($this->format === 'json') { if (!$json = json_decode((string) $contents, true)) { throw new UnexpectedValueException( 'Unable to decode JSON file' ); } if (!isset($json[$this->subjectTokenFieldName])) { throw new UnexpectedValueException( 'subject_token_field_name not found in JSON file' ); } $contents = $json[$this->subjectTokenFieldName]; } return $contents; } }