/** * @param \ReflectionClass $reflectionClass * @param \ReflectionClass[] $interfaces * @return ProxyClass */ public function get(\ReflectionClass $reflectionClass, $interfaces = []) { $key = $this->makeKey(array_merge([$reflectionClass], $interfaces)); if (!isset($this->classMap[$key])) { $this->classMap[$key] = $this->enhancedClassFactory->get($reflectionClass, $interfaces); } return $this->classMap[$key]; }
public function test() { $proxyStdClass1 = $this->cachedProxyClassFactory->get(new ReflectionClass(\stdClass::class), []); $this->assertInstanceOf(ProxyClass::class, $proxyStdClass1); $proxyStdClass2 = $this->cachedProxyClassFactory->get(new ReflectionClass(\stdClass::class), []); $this->assertInstanceOf(ProxyClass::class, $proxyStdClass2); $this->assertEquals($proxyStdClass1, $proxyStdClass2); $proxySoapClient = $this->cachedProxyClassFactory->get(new ReflectionClass(\SoapClient::class), []); $this->assertInstanceOf(ProxyClass::class, $proxySoapClient); $this->assertEquals($proxyStdClass1, $proxySoapClient); }
/** * @param string|string[] $classOrInterfaces * @return ProxyClass * @throws \ReflectionException */ private function get($classOrInterfaces) { if (!is_array($classOrInterfaces)) { $classOrInterfaces = [$classOrInterfaces]; } $class = $this->extractReflectionClass($classOrInterfaces); $interfaces = $this->extractReflectionInterfaces($classOrInterfaces); if ($class->isFinal()) { throw new ProxyException("Cannot proxy class that is final! " . $class->getName()); } if (count($interfaces) + 1 < count($classOrInterfaces)) { throw new ProxyException('Something went wrong :)'); } $proxyClass = $this->proxyClassFactory->get($class, $interfaces); return $proxyClass; }