Go\Instrument\Transformer\WeavingTransformer::saveProxyToCache PHP Method

saveProxyToCache() private method

Save AOP proxy to the separate file anr returns the php source code for inclusion
private saveProxyToCache ( ReflectionClas\ReflectionClass $class, string | ClassProxy $child ) : string
$class ReflectionClas\ReflectionClass Original class reflection
$child string | Go\Proxy\ClassProxy
return string
    private function saveProxyToCache($class, $child)
    {
        static $cacheDirSuffix = '/_proxies/';
        $cacheDir = $this->cachePathManager->getCacheDir();
        // Without cache we should rewrite original file
        if (!$cacheDir) {
            return $child;
        }
        $cacheDir = $cacheDir . $cacheDirSuffix;
        $fileName = str_replace($this->options['appDir'] . DIRECTORY_SEPARATOR, '', $class->getFileName());
        $proxyFileName = $cacheDir . $fileName;
        $dirname = dirname($proxyFileName);
        if (!file_exists($dirname)) {
            mkdir($dirname, $this->options['cacheFileMode'], true);
        }
        $body = '<?php' . PHP_EOL;
        $namespace = $class->getNamespaceName();
        if ($namespace) {
            $body .= "namespace {$namespace};" . PHP_EOL . PHP_EOL;
        }
        $refNamespace = new ReflectionFileNamespace($class->getFileName(), $namespace);
        foreach ($refNamespace->getNamespaceAliases() as $fqdn => $alias) {
            $body .= "use {$fqdn} as {$alias};" . PHP_EOL;
        }
        $body .= $child;
        file_put_contents($proxyFileName, $body, LOCK_EX);
        // For cache files we don't want executable bits by default
        chmod($proxyFileName, $this->options['cacheFileMode'] & ~0111);
        return 'include_once AOP_CACHE_DIR . ' . var_export($cacheDirSuffix . $fileName, true) . ';' . PHP_EOL;
    }