@@ -25,22 +25,27 @@ final class AccessPolicy
2525
2626
2727 public function __construct (
28- private readonly Component $ component ,
2928 private readonly \ReflectionClass |\ReflectionMethod $ element ,
3029 ) {
3130 }
3231
3332
34- public function checkAccess (): void
33+ public function checkAccess (Component $ component ): void
3534 {
35+ $ this ->presenter ??= $ component ->getPresenterIfExists () ??
36+ throw new Nette \InvalidStateException ('Presenter is required for checking requirements of ' . Reflection::toString ($ this ->element ));
37+
3638 $ attrs = $ this ->getAttributes ();
37- $ attrs = self ::applyInternalRules ($ attrs );
39+ $ attrs = self ::applyInternalRules ($ attrs, $ component );
3840 foreach ($ attrs as $ attribute ) {
3941 $ this ->checkAttribute ($ attribute );
4042 }
4143 }
4244
4345
46+ /**
47+ * @return Attributes\Requires[]
48+ */
4449 private function getAttributes (): array
4550 {
4651 return array_map (
@@ -50,11 +55,11 @@ private function getAttributes(): array
5055 }
5156
5257
53- private function applyInternalRules (array $ attrs ): array
58+ private function applyInternalRules (array $ attrs, Component $ component ): array
5459 {
5560 if (
5661 $ this ->element instanceof \ReflectionMethod
57- && str_starts_with ($ this ->element ->getName (), $ this -> component ::formatSignalMethod ('' ))
62+ && str_starts_with ($ this ->element ->getName (), $ component ::formatSignalMethod ('' ))
5863 && !ComponentReflection::parseAnnotation ($ this ->element , 'crossOrigin ' )
5964 && !Nette \Utils \Arrays::some ($ attrs , fn ($ attr ) => $ attr ->sameOrigin === false )
6065 ) {
@@ -66,9 +71,6 @@ private function applyInternalRules(array $attrs): array
6671
6772 private function checkAttribute (Attributes \Requires $ attribute ): void
6873 {
69- $ this ->presenter ??= $ this ->component ->getPresenterIfExists () ??
70- throw new Nette \InvalidStateException ('Presenter is required for checking requirements of ' . Reflection::toString ($ this ->element ));
71-
7274 if ($ attribute ->methods !== null ) {
7375 $ this ->checkHttpMethod ($ attribute );
7476 }
0 commit comments