mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 02:54:03 +00:00
Revert try/catch removal, add/update comments
This commit is contained in:
parent
376f7ba0b0
commit
9262d95ce4
2 changed files with 10 additions and 13 deletions
|
|
@ -21,9 +21,9 @@ trait BelongsToTenant
|
||||||
|
|
||||||
public static function bootBelongsToTenant(): void
|
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
|
// 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);
|
static::addGlobalScope(new TenantScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ use Symfony\Component\Finder\SplFileInfo;
|
||||||
|
|
||||||
trait DealsWithModels
|
trait DealsWithModels
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* If this is not null, use this instead of the default model discovery logic.
|
||||||
|
*/
|
||||||
public static Closure|null $modelDiscoveryOverride = null;
|
public static Closure|null $modelDiscoveryOverride = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -27,19 +30,13 @@ trait DealsWithModels
|
||||||
|
|
||||||
return array_filter(array_map(function (SplFileInfo $file) {
|
return array_filter(array_map(function (SplFileInfo $file) {
|
||||||
$fileContents = str($file->getContents());
|
$fileContents = str($file->getContents());
|
||||||
$className = $fileContents->after('class ')->before("\n")->explode(' ')->first();
|
$class = $fileContents->after('class ')->before("\n")->explode(' ')->first();
|
||||||
|
|
||||||
if ($fileContents->contains('namespace ')) {
|
if ($fileContents->contains('namespace ')) {
|
||||||
/** @var class-string $fullClassName */
|
try {
|
||||||
$fullClassName = $fileContents->after('namespace ')->before(';')->toString() . '\\' . $className;
|
return new ($fileContents->after('namespace ')->before(';')->toString() . '\\' . $class);
|
||||||
|
} catch (\Throwable $th) {
|
||||||
// Skip non-instantiable classes – we only care about models, and those are instantiable
|
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue