@@ 83-114 (lines=32) @@ | ||
80 | $this->denyAccessAttribute = $options['deny-access-attribute']; |
|
81 | } |
|
82 | ||
83 | public function invokeEntityMethod(Request $request, string $entityId): Response |
|
84 | { |
|
85 | /** @var object|null $entity */ |
|
86 | $entity = $this->controllerHelper->findEntity($this->entityClass, $entityId); |
|
87 | ||
88 | if (is_null($entity)) { |
|
89 | throw new InvalidArgumentException(sprintf( |
|
90 | "Entity with id '%s' not found!", |
|
91 | $entityId |
|
92 | )); |
|
93 | } |
|
94 | ||
95 | if (!empty($this->denyAccessAttribute)) { |
|
96 | $this->controllerHelper->denyAccessUnlessGranted($this->denyAccessAttribute, $entity); |
|
97 | } |
|
98 | ||
99 | $reflectionObject = new ReflectionObject($entity); |
|
100 | ||
101 | /** @var ReflectionMethod $reflectionMethod */ |
|
102 | $reflectionMethod = $reflectionObject->getMethod($this->methodName); |
|
103 | ||
104 | /** @var array $callArguments */ |
|
105 | $callArguments = $this->argumentCompiler->buildCallArguments( |
|
106 | $reflectionMethod, |
|
107 | $this->arguments, |
|
108 | $request |
|
109 | ); |
|
110 | ||
111 | $reflectionMethod->invokeArgs($entity, $callArguments); |
|
112 | ||
113 | return new Response("Entity method invoked!"); |
|
114 | } |
|
115 | ||
116 | } |
|
117 |
@@ 87-118 (lines=32) @@ | ||
84 | $this->authorizationAttribute = $options['authorization-attributes']; |
|
85 | } |
|
86 | ||
87 | public function callService(Request $request): Response |
|
88 | { |
|
89 | if (!is_null($this->authorizationAttribute)) { |
|
90 | $this->controllerHelper->denyAccessUnlessGranted($this->authorizationAttribute, $request); |
|
91 | } |
|
92 | ||
93 | /** @var object|null $service */ |
|
94 | $service = $this->container->get($this->serviceId); |
|
95 | ||
96 | if (is_null($service)) { |
|
97 | throw new ErrorException(sprintf( |
|
98 | "Could not find service '%s'!", |
|
99 | $this->serviceId |
|
100 | )); |
|
101 | } |
|
102 | ||
103 | $reflectionObject = new ReflectionObject($service); |
|
104 | ||
105 | /** @var ReflectionMethod $reflectionMethod */ |
|
106 | $reflectionMethod = $reflectionObject->getMethod($this->method); |
|
107 | ||
108 | /** @var array $arguments */ |
|
109 | $arguments = $this->argumentCompiler->buildCallArguments( |
|
110 | $reflectionMethod, |
|
111 | $this->arguments, |
|
112 | $request |
|
113 | ); |
|
114 | ||
115 | $reflectionMethod->invokeArgs($service, $arguments); |
|
116 | ||
117 | return new Response("Service call completed"); |
|
118 | } |
|
119 | ||
120 | } |
|
121 |