generateProxyClass example

public function generateProxyClasses(array $classes$proxyDir = null)
    {
        $generated = 0;

        foreach ($classes as $class) {
            if ($this->skipClass($class)) {
                continue;
            }

            $proxyFileName = $this->proxyGenerator->getProxyFileName($class->getName()$proxyDir);

            $this->proxyGenerator->generateProxyClass($class$proxyFileName);

            $generated += 1;
        }

        return $generated;
    }

    /** * Reset initialization/cloning logic for an un-initialized proxy * * @return Proxy * * @throws InvalidArgumentException */
EOF;
    }

    public function getProxyCode(Definition $definition, string $id = null): string
    {
        $code = $this->classGenerator->generate($this->generateProxyClass($definition));
        $code = preg_replace('/^(class [^ ]++ extends )([^\\\\])/', '$1\\\\$2', $code);

        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
    {
if (!is_readable($proxyFile)) {
            if (!file_exists($this->proxyDir)) {
                if (!mkdir($concurrentDirectory = $this->proxyDir) && !is_dir($concurrentDirectory)) {
                    throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
                }
            }
            if (!is_writable($this->proxyDir)) {
                throw new \RuntimeException(sprintf('The directory "%s" is not writable.', $this->proxyDir));
            }

            $content = $this->generateProxyClass($class);
            $this->writeProxyClass($proxyFile$content);
        } elseif (!method_exists($proxy, 'executeParent')) {
            @unlink($proxyFile);
        }

        return $proxy;
    }

    /** * Returns proxy class name * * @param string $class * * @return string */
Home | Imprint | This part of the site doesn't use cookies.