diff --git a/src/Contracts/Institution.php b/src/Contracts/Institution.php index f0561a8..de9b20d 100644 --- a/src/Contracts/Institution.php +++ b/src/Contracts/Institution.php @@ -8,4 +8,5 @@ interface Institution * Define the name used to identify this Schools entry in the config. */ public function getConfigName(): string; + public static function default(): Institution; } diff --git a/src/Endpoint.php b/src/Endpoint.php index 2111cd0..13ccccc 100644 --- a/src/Endpoint.php +++ b/src/Endpoint.php @@ -16,25 +16,44 @@ abstract class Endpoint /** * @var Guzzle */ - protected $guzzle; + protected Guzzle $guzzle; /** * @var Institution */ - protected $institution; + protected Institution $institution; /** * @var string */ - protected $endpoint; + protected string $endpoint; - public function __construct(Institution $institution) + /** + * @throws Exception + */ + public function __construct(?Institution $institution = null) { - $this->institution = $institution; + $this->setInstitution($institution); $this->setGuzzle(); $this->setEndpoint(); } + /** + * @throws Exception + */ + protected function setInstitution(Institution $institution): void + { + $this->institution = $institution; + + if ($this->institution === null) { + if (function_exists('defaultIsamsInstitution')) { + $this->institution = defaultIsamsInstitution(); + } else { + throw new Exception('No Institution provided and no default Institution set.'); + } + } + } + /** * Instantiate Guzzle. *