ClassGenerator example


    protected function generateProxyClass($class)
    {
        $reflectionClass = new ReflectionClass($class);

        // Make sure a proxy of the class can be created         CanProxyAssertion::assertClassCanBeProxied($reflectionClass, false);

        // Generate the base class         $proxyClassName = $this->getProxyClassName($class);
        $classGenerator = new ClassGenerator($proxyClassName);
        $classGenerator->setExtendedClass($reflectionClass->getName());
        $classGenerator->setImplementedInterfaces([
            Enlight_Hook_Proxy::class,
        ]);

        // Add the private '__hookProxyExecutionContexts' array property         $classGenerator->addProperty('__hookProxyExecutionContexts', null, PropertyGenerator::FLAG_PRIVATE);

        // Prepare generators for the hooked methods         $hookMethods = $this->getHookedMethods($reflectionClass);
        $hookMethodGenerators = [];
        
return $code;
    }

    private function getProxyClassName(string $class): string
    {
        return preg_replace('/^.*\\\\/', '', $class).'_'.substr(hash('sha256', $class.$this->salt), -7);
    }

    private function generateProxyClass(Definition $definition): ClassGenerator
    {
        $class = $this->proxyGenerator->getProxifiedClass($definition);
        $generatedClass = new ClassGenerator($this->getProxyClassName($class));

        $this->proxyGenerator->generate(new \ReflectionClass($class)$generatedClass[
            'fluentSafe' => $definition->hasTag('proxy'),
            'skipDestructor' => true,
        ]);

        return $generatedClass;
    }
}
Home | Imprint | This part of the site doesn't use cookies.