예제 #1
0
 /**
  * Save AOP proxy to the separate file anr returns the php source code for inclusion
  *
  * @param ParsedClass $class Original class reflection
  * @param string|ClassProxy $child
  *
  * @return string
  */
 private function saveProxyToCache($class, $child)
 {
     // Without cache we should rewrite original file
     if (empty($this->options['cacheDir'])) {
         return $child;
     }
     $cacheDirSuffix = '/_proxies/';
     $cacheDir = $this->options['cacheDir'] . $cacheDirSuffix;
     $fileName = str_replace($this->options['appDir'] . DIRECTORY_SEPARATOR, '', $class->getFileName());
     $proxyFileName = $cacheDir . $fileName;
     $dirname = dirname($proxyFileName);
     if (!file_exists($dirname)) {
         mkdir($dirname, 0770, true);
     }
     $body = '<?php' . PHP_EOL;
     $namespace = $class->getNamespaceName();
     if ($namespace) {
         $body .= "namespace {$namespace};" . PHP_EOL . PHP_EOL;
     }
     foreach ($class->getNamespaceAliases() as $alias => $fqdn) {
         $body .= "use {$fqdn} as {$alias};" . PHP_EOL;
     }
     $body .= $child;
     file_put_contents($proxyFileName, $body);
     return 'include_once AOP_CACHE_DIR . ' . var_export($cacheDirSuffix . $fileName, true) . ';' . PHP_EOL;
 }