public function testProxyRenderer() { $ref1 = ReflectorFactory::buildReflectorByClassName(MethodReflectionTestObject::class); $crclass = $ref1->getCompactReferenceClass(); // print_r($crclass->toArray()); $renderer = new ProxyRenderer($crclass, 'RandomProxyName_ds8bfgFHGTG4'); $renderedClass = $renderer->render(); $injector = new Injector(null); $provider = ClassProvider::init(MethodReflectionTestObject::class); /** @var MethodReflectionTestObject $proxy */ $proxy = null; eval($renderedClass . '$proxy = new \\Brunt\\ProxyObject\\RandomProxyName_ds8bfgFHGTG4($provider, $injector);'); $this->assertInstanceOf(MethodReflectionTestObject::class, $proxy); }
public function create(Injector $injector, ClassProviderInterface $provider) { $t1 = microtime(true); $proxy = null; $reflector = $provider->getReflector(); $className = $reflector->getClassName(); $proxyClassName = $this->getProxyClassName($className); if (isset(self::$classNames[$className])) { $proxyNSClassName = 'Brunt\\ProxyObject\\' . $proxyClassName; $proxy = new $proxyNSClassName($provider, $injector); $t2 = microtime(true); self::$t1 += $t2 - $t1; } else { if ($this->cache->read($reflector, $proxyClassName)) { self::$t2_ += microtime(true) - $t1; $proxyNSClassName = 'Brunt\\ProxyObject\\' . $proxyClassName; $proxy = new $proxyNSClassName($provider, $injector); $t2 = microtime(true); self::$t2 += $t2 - $t1; } else { $renderer = new ProxyRenderer($reflector->getCompactReferenceClass(), $proxyClassName); $class = $renderer->__toString(); eval($class); $proxyNSClassName = 'Brunt\\ProxyObject\\' . $proxyClassName; $proxy = new $proxyNSClassName($provider, $injector); $this->cache->write($class, $reflector, $proxyClassName); $t2 = microtime(true); self::$t3 += $t2 - $t1; } } if ($proxy == null) { throw new ProxyBuildErrorException("something went horribly wrong:\nplease inform the maintainer of brunt!\nthis should never happen, therefore it is a major issue"); } self::$classNames[$className] = $proxyClassName; return $proxy; }