Skip to content

Commit

Permalink
feat: allow institution to be null if the consuming app has a default…
Browse files Browse the repository at this point in the history
… instition function set
  • Loading branch information
fredbradley committed Jul 30, 2024
1 parent 94ecfcb commit f9f0e0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Contracts/Institution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
29 changes: 24 additions & 5 deletions src/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit f9f0e0a

Please # to comment.