Skip to content

Commit bf145da

Browse files
authored
Update ParseCustomPolicyActions.php
1 parent 748c9b4 commit bf145da

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/Http/Middleware/ParseCustomPolicyActions.php

+18-14
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,29 @@ protected function registerCustomPolicyActions(): void
8484

8585
protected function getCustomActionMethods(string $policyClass): Collection
8686
{
87-
$parentClass = new ReflectionClass(get_parent_class($policyClass));
88-
$parentMethods = collect($parentClass->getMethods(ReflectionMethod::IS_PUBLIC))
89-
->pluck("name");
90-
$class = new ReflectionClass($policyClass);
91-
$methods = collect($class->getMethods(ReflectionMethod::IS_PUBLIC))
92-
->pluck("name");
87+
return cache()->remember("genealabs:laravel-governor:custom-action-methods", 300, function () use ($policyClass): Collection {
88+
$parentClass = new ReflectionClass(get_parent_class($policyClass));
89+
$parentMethods = collect($parentClass->getMethods(ReflectionMethod::IS_PUBLIC))
90+
->pluck("name");
91+
$class = new ReflectionClass($policyClass);
92+
$methods = collect($class->getMethods(ReflectionMethod::IS_PUBLIC))
93+
->pluck("name");
9394

94-
return $methods
95-
->diff($parentMethods)
96-
->sort();
95+
return $methods
96+
->diff($parentMethods)
97+
->sort();
98+
});
9799
}
98100

99101
protected function getPolicies(): Collection
100102
{
101-
$gate = app('Illuminate\Contracts\Auth\Access\Gate');
102-
$reflectedGate = new ReflectionObject($gate);
103-
$policies = $reflectedGate->getProperty("policies");
104-
$policies->setAccessible(true);
103+
return cache()->remember("genealabs:laravel-governor:policies", 300, function (): Collection {
104+
$gate = app('Illuminate\Contracts\Auth\Access\Gate');
105+
$reflectedGate = new ReflectionObject($gate);
106+
$policies = $reflectedGate->getProperty("policies");
107+
$policies->setAccessible(true);
105108

106-
return collect($policies->getValue($gate));
109+
return collect($policies->getValue($gate));
110+
});
107111
}
108112
}

0 commit comments

Comments
 (0)