1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-04 19:24:02 +00:00

Revert try/catch removal, add/update comments

This commit is contained in:
lukinovec 2023-06-19 15:24:39 +02:00
parent 376f7ba0b0
commit 9262d95ce4
2 changed files with 10 additions and 13 deletions

View file

@ -21,9 +21,9 @@ trait BelongsToTenant
public static function bootBelongsToTenant(): void
{
// If tenancy.rls.enabled is true or this model implements RlsModel
// If 'tenancy.rls.enabled' is true or this model implements RlsModel
// Scope queries using Postgres RLS instead of TenantScope
if (! (config('tenancy.rls.enabled') || (new static) instanceof RLSModel)) {
if (! (config('tenancy.rls.enabled') || (new static) instanceof RlsModel)) {
static::addGlobalScope(new TenantScope);
}

View file

@ -12,6 +12,9 @@ use Symfony\Component\Finder\SplFileInfo;
trait DealsWithModels
{
/**
* If this is not null, use this instead of the default model discovery logic.
*/
public static Closure|null $modelDiscoveryOverride = null;
/**
@ -27,19 +30,13 @@ trait DealsWithModels
return array_filter(array_map(function (SplFileInfo $file) {
$fileContents = str($file->getContents());
$className = $fileContents->after('class ')->before("\n")->explode(' ')->first();
$class = $fileContents->after('class ')->before("\n")->explode(' ')->first();
if ($fileContents->contains('namespace ')) {
/** @var class-string $fullClassName */
$fullClassName = $fileContents->after('namespace ')->before(';')->toString() . '\\' . $className;
// Skip non-instantiable classes we only care about models, and those are instantiable
if ((new ReflectionClass($fullClassName))->getConstructor()?->getNumberOfRequiredParameters() === 0) {
$object = new $fullClassName;
if ($object instanceof Model) {
return $object;
}
try {
return new ($fileContents->after('namespace ')->before(';')->toString() . '\\' . $class);
} catch (\Throwable $th) {
// Skip non-instantiable classes we only care about models, and those are instantiable
}
}