Skip to content

Commit f9f0e0a

Browse files
committed
feat: allow institution to be null if the consuming app has a default instition function set
1 parent 94ecfcb commit f9f0e0a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/Contracts/Institution.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ interface Institution
88
* Define the name used to identify this Schools entry in the config.
99
*/
1010
public function getConfigName(): string;
11+
public static function default(): Institution;
1112
}

src/Endpoint.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,44 @@ abstract class Endpoint
1616
/**
1717
* @var Guzzle
1818
*/
19-
protected $guzzle;
19+
protected Guzzle $guzzle;
2020

2121
/**
2222
* @var Institution
2323
*/
24-
protected $institution;
24+
protected Institution $institution;
2525

2626
/**
2727
* @var string
2828
*/
29-
protected $endpoint;
29+
protected string $endpoint;
3030

31-
public function __construct(Institution $institution)
31+
/**
32+
* @throws Exception
33+
*/
34+
public function __construct(?Institution $institution = null)
3235
{
33-
$this->institution = $institution;
36+
$this->setInstitution($institution);
3437
$this->setGuzzle();
3538
$this->setEndpoint();
3639
}
3740

41+
/**
42+
* @throws Exception
43+
*/
44+
protected function setInstitution(Institution $institution): void
45+
{
46+
$this->institution = $institution;
47+
48+
if ($this->institution === null) {
49+
if (function_exists('defaultIsamsInstitution')) {
50+
$this->institution = defaultIsamsInstitution();
51+
} else {
52+
throw new Exception('No Institution provided and no default Institution set.');
53+
}
54+
}
55+
}
56+
3857
/**
3958
* Instantiate Guzzle.
4059
*

0 commit comments

Comments
 (0)