-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Abstract out tenancy options for hydration to flag class
- Loading branch information
Showing
3 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Sprout; | ||
|
||
use Sprout\Contracts\Tenancy; | ||
|
||
class TenancyOptions | ||
{ | ||
/** | ||
* Tenant relations should be automatically hydrated | ||
* | ||
* @return string | ||
*/ | ||
public static function hydrateTenantRelation(): string | ||
{ | ||
return 'tenant-relation.hydrate'; | ||
} | ||
|
||
/** | ||
* Check whether a model relates to the tenant before hydrating | ||
* | ||
* @return string | ||
*/ | ||
public static function checkForRelationWithTenant(): string | ||
{ | ||
return 'tenant-relation.check'; | ||
} | ||
|
||
/** | ||
* Throw an exception if the model isn't related to the tenant | ||
* | ||
* @return string | ||
*/ | ||
public static function throwIfNotRelated(): string | ||
{ | ||
return 'tenant-relation.strict'; | ||
} | ||
|
||
/** | ||
* @param \Sprout\Contracts\Tenancy<\Sprout\Contracts\Tenant> $tenancy | ||
* | ||
* @return bool | ||
*/ | ||
public static function shouldHydrateTenantRelation(Tenancy $tenancy): bool | ||
{ | ||
return (bool)$tenancy->option(static::hydrateTenantRelation(), true); | ||
} | ||
|
||
/** | ||
* @param \Sprout\Contracts\Tenancy<\Sprout\Contracts\Tenant> $tenancy | ||
* | ||
* @return bool | ||
*/ | ||
public static function shouldCheckForRelationWithTenant(Tenancy $tenancy): bool | ||
{ | ||
return (bool)$tenancy->option(static::checkForRelationWithTenant(), true); | ||
} | ||
|
||
/** | ||
* @param \Sprout\Contracts\Tenancy<\Sprout\Contracts\Tenant> $tenancy | ||
* | ||
* @return bool | ||
*/ | ||
public static function shouldThrowIfNotRelated(Tenancy $tenancy): bool | ||
{ | ||
return (bool)$tenancy->option(static::throwIfNotRelated(), false); | ||
} | ||
} |