| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Contract\Core\Provider; |
| 4: | |
| 5: | use Salient\Contract\Container\HasContainer; |
| 6: | use Salient\Contract\Core\Exception\MethodNotImplementedException; |
| 7: | use Salient\Contract\Core\DateFormatterInterface; |
| 8: | use Salient\Contract\Core\HasName; |
| 9: | use Stringable; |
| 10: | |
| 11: | /** |
| 12: | * @api |
| 13: | * |
| 14: | * @template TContext of ProviderContextInterface |
| 15: | */ |
| 16: | interface ProviderInterface extends HasContainer, HasName |
| 17: | { |
| 18: | /** |
| 19: | * Get the name of the provider |
| 20: | * |
| 21: | * Appropriate values to return are: |
| 22: | * |
| 23: | * - already in scope (no lookup or transformation required) |
| 24: | * - likely to be unique |
| 25: | * - human-readable |
| 26: | */ |
| 27: | public function getName(): string; |
| 28: | |
| 29: | /** |
| 30: | * Get a stable list of values that, together with the name of the class, |
| 31: | * uniquely identifies the provider's backend instance |
| 32: | * |
| 33: | * This method must be idempotent for each backend instance the provider |
| 34: | * connects to. The return value should correspond to the smallest possible |
| 35: | * set of stable metadata that uniquely identifies the specific data source |
| 36: | * backing the connected instance. |
| 37: | * |
| 38: | * This may include: |
| 39: | * |
| 40: | * - an endpoint URI (if backend instances are URI-specific or can be |
| 41: | * expressed as an immutable URI) |
| 42: | * - a tenant ID |
| 43: | * - an installation GUID |
| 44: | * |
| 45: | * It should not include: |
| 46: | * |
| 47: | * - usernames, API keys, tokens, or other identifiers with a shorter |
| 48: | * lifespan than the data source itself |
| 49: | * - values that aren't unique to the connected data source |
| 50: | * - case-insensitive values (unless normalised first) |
| 51: | * |
| 52: | * It must not include: |
| 53: | * |
| 54: | * - values retrieved from a provider at runtime |
| 55: | * |
| 56: | * @return array<int|float|string|bool|Stringable|null> |
| 57: | */ |
| 58: | public function getBackendIdentifier(): array; |
| 59: | |
| 60: | /** |
| 61: | * Get a date formatter to work with the provider's date and time format |
| 62: | * and/or timezone |
| 63: | */ |
| 64: | public function getDateFormatter(): DateFormatterInterface; |
| 65: | |
| 66: | /** |
| 67: | * Get a context within which to instantiate entities on the provider's |
| 68: | * behalf |
| 69: | * |
| 70: | * @return TContext |
| 71: | */ |
| 72: | public function getContext(): ProviderContextInterface; |
| 73: | |
| 74: | /** |
| 75: | * Throw an exception if the provider's backend isn't reachable |
| 76: | * |
| 77: | * Positive results should be cached for `$ttl` seconds. Negative results |
| 78: | * must never be cached. |
| 79: | * |
| 80: | * @return $this |
| 81: | * @throws MethodNotImplementedException if heartbeat monitoring isn't |
| 82: | * supported. |
| 83: | */ |
| 84: | public function checkHeartbeat(int $ttl = 300); |
| 85: | } |
| 86: |