Closed sdemirov closed 6 months ago
@leeqvip
@sdemirov You can initialize the adapter before the Enforcer is created
$this->app->singleton(DatabaseAdapter.class, function($app){
$adapter = new DatabaseAdapter(new Rule([], $name));
$adapter->setFiltered(true);
return $adapter;
});
Great! Thank you very much.
Is there any way to call
Enforcer::loadFilteredPolicy($filter);
without calling loadPolicy on Enforcer creation?In CoreEnforcer.php there is such logic:
// Do not initialize the full policy when using a filtered adapter
$ok = $this->adapter instanceof FilteredAdapter ? $this->adapter->isFiltered() : false;
if (!\is_null($this->adapter) && !$ok) {
$this->loadPolicy();
}
but
$this->adapter->isFiltered()
isfalse
, because is called on Enforcer creation and$this->setFiltered(true)
is called inloadFilteredPolicy