give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Resources
/
Concerns
/
RebindsAuthState.php
give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Resources
/
Concerns
Last commit date
RebindsAuthState.php
3 months ago
RebindsRequestHeaderCollection.php
3 months ago
RebindsAuthState.php
46 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Give\Vendors\LiquidWeb\LicensingApiClient\Resources\Concerns; |
| 4 | |
| 5 | use Give\Vendors\LiquidWeb\LicensingApiClient\Http\AuthState; |
| 6 | use Give\Vendors\LiquidWeb\LicensingApiClient\Resources\Credit\CreditsLedgerResource; |
| 7 | use Give\Vendors\LiquidWeb\LicensingApiClient\Resources\Credit\CreditsPoolsResource; |
| 8 | use Give\Vendors\LiquidWeb\LicensingApiClient\Resources\Credit\CreditsQuotasResource; |
| 9 | use Give\Vendors\LiquidWeb\LicensingApiClient\Resources\Credit\CreditsResource; |
| 10 | use Give\Vendors\LiquidWeb\LicensingApiClient\Resources\EntitlementsResource; |
| 11 | use Give\Vendors\LiquidWeb\LicensingApiClient\Resources\LicensesResource; |
| 12 | use Give\Vendors\LiquidWeb\LicensingApiClient\Resources\ProductsResource; |
| 13 | use Give\Vendors\LiquidWeb\LicensingApiClient\Resources\TokensResource; |
| 14 | |
| 15 | /** |
| 16 | * Provides immutable auth-state rebinding for auth-bound resource views. |
| 17 | * |
| 18 | * @mixin CreditsLedgerResource |
| 19 | * @mixin CreditsPoolsResource |
| 20 | * @mixin CreditsQuotasResource |
| 21 | * @mixin CreditsResource |
| 22 | * @mixin EntitlementsResource |
| 23 | * @mixin LicensesResource |
| 24 | * @mixin ProductsResource |
| 25 | * @mixin TokensResource |
| 26 | */ |
| 27 | trait RebindsAuthState |
| 28 | { |
| 29 | /** |
| 30 | * Returns the current resource when the auth state is unchanged, or a rebound |
| 31 | * resource view when a different auth state is requested. |
| 32 | */ |
| 33 | public function withAuthState(AuthState $authState): self { |
| 34 | if ($this->authState === $authState) { |
| 35 | return $this; |
| 36 | } |
| 37 | |
| 38 | return $this->rebindWithAuthState($authState); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Rebuilds the concrete resource with the provided auth state. |
| 43 | */ |
| 44 | abstract protected function rebindWithAuthState(AuthState $authState): self; |
| 45 | } |
| 46 |