/** * Compile the result of methods marked with CompileStatic into the proxy class * * @param string $className * @param \TYPO3\Flow\Object\Proxy\ProxyClass $proxyClass * @return void */ protected function compileStaticMethods($className, $proxyClass) { if ($this->classesWithCompileStaticAnnotation === null) { $this->classesWithCompileStaticAnnotation = array_flip($this->reflectionService->getClassesContainingMethodsAnnotatedWith(\TYPO3\Flow\Annotations\CompileStatic::class)); } if (!isset($this->classesWithCompileStaticAnnotation[$className])) { return; } $methodNames = get_class_methods($className); foreach ($methodNames as $methodName) { if ($this->reflectionService->isMethodStatic($className, $methodName) && $this->reflectionService->isMethodAnnotatedWith($className, $methodName, \TYPO3\Flow\Annotations\CompileStatic::class)) { $compiledMethod = $proxyClass->getMethod($methodName); $value = call_user_func(array($className, $methodName), $this->objectManager); $compiledResult = var_export($value, true); $compiledMethod->setMethodBody('return ' . $compiledResult . ';'); } } }
/** * Compile the result of methods marked with CompileStatic into the proxy class * * @param string $className * @param ProxyClass $proxyClass * @return void * @throws ObjectException */ protected function compileStaticMethods($className, ProxyClass $proxyClass) { $methodNames = $this->reflectionService->getMethodsAnnotatedWith($className, Flow\CompileStatic::class); foreach ($methodNames as $methodName) { if (!$this->reflectionService->isMethodStatic($className, $methodName)) { throw new ObjectException(sprintf('The method %s:%s() is annotated CompileStatic so it must be static', $className, $methodName), 1476348303); } if ($this->reflectionService->isMethodPrivate($className, $methodName)) { throw new ObjectException(sprintf('The method %s:%s() is annotated CompileStatic so it must not be private', $className, $methodName), 1476348306); } $reflectedMethod = new MethodReflection($className, $methodName); $reflectedMethod->setAccessible(true); $value = $reflectedMethod->invoke(null, $this->objectManager); $compiledResult = var_export($value, true); $compiledMethod = $proxyClass->getMethod($methodName); $compiledMethod->setMethodBody('return ' . $compiledResult . ';'); } }