. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ namespace Espo\Core\Acl\AssignmentChecker; use Espo\ORM\Entity; use Espo\Entities\User; use Espo\Core\Acl\AssignmentChecker; class AssignmentCheckerManager { /** @var array> */ private $checkerCache = []; public function __construct(private AssignmentCheckerFactory $factory) {} public function check(User $user, Entity $entity): bool { $entityType = $entity->getEntityType(); $checker = $this->getChecker($entityType); return $checker->check($user, $entity); } /** * @return AssignmentChecker */ private function getChecker(string $entityType): AssignmentChecker { if (!array_key_exists($entityType, $this->checkerCache)) { $this->loadChecker($entityType); } return $this->checkerCache[$entityType]; } private function loadChecker(string $entityType): void { $this->checkerCache[$entityType] = $this->factory->create($entityType); } }