From 4772ff80d38c388a736972bdd63a0c0f8a429162 Mon Sep 17 00:00:00 2001 From: Paul Radt Date: Thu, 31 Oct 2024 09:13:22 +0100 Subject: [PATCH 1/2] Improve performance by using clone in stead of the newInstance method --- src/PermissionRegistrar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PermissionRegistrar.php b/src/PermissionRegistrar.php index 38362990..a7322376 100644 --- a/src/PermissionRegistrar.php +++ b/src/PermissionRegistrar.php @@ -360,7 +360,7 @@ private function getHydratedPermissionCollection(): Collection $permissionInstance = new ($this->getPermissionClass())(); return Collection::make(array_map( - fn ($item) => $permissionInstance->newInstance([], true) + fn ($item) => (clone $permissionInstance) ->setRawAttributes($this->aliasedArray(array_diff_key($item, ['r' => 0])), true) ->setRelation('roles', $this->getHydratedRoleCollection($item['r'] ?? [])), $this->permissions['permissions'] @@ -379,7 +379,7 @@ private function hydrateRolesCache(): void $roleInstance = new ($this->getRoleClass())(); array_map(function ($item) use ($roleInstance) { - $role = $roleInstance->newInstance([], true) + $role = (clone $roleInstance) ->setRawAttributes($this->aliasedArray($item), true); $this->cachedRoles[$role->getKey()] = $role; }, $this->permissions['roles']); From 5f483f51204bd17b89372e03ca3472e1cebac8bf Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 4 Nov 2024 08:27:43 -0800 Subject: [PATCH 2/2] Fix typo Fixed a very serious issue <3 --- src/PermissionRegistrar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PermissionRegistrar.php b/src/PermissionRegistrar.php index a7322376..45d5d223 100644 --- a/src/PermissionRegistrar.php +++ b/src/PermissionRegistrar.php @@ -199,7 +199,7 @@ private function loadPermissions(): void $this->cacheKey, $this->cacheExpirationTime, fn () => $this->getSerializedPermissionsForCache() ); - // fallback for old cache method, must be removed on next mayor version + // fallback for old cache method, must be removed on next major version if (! isset($this->permissions['alias'])) { $this->forgetCachedPermissions(); $this->loadPermissions();