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;
}