示例#1
0
 /**
  * {@inheritDoc}
  */
 public function __invoke($className)
 {
     if (class_exists($className, false) || !$this->classNameInflector->isProxyClassName($className)) {
         return false;
     }
     $file = $this->fileLocator->getProxyFileName($className);
     if (!file_exists($file)) {
         return false;
     }
     return (bool) (require_once $file);
 }
示例#2
0
 /**
  * {@inheritDoc}
  */
 public function __invoke(string $className) : bool
 {
     if (class_exists($className, false) || !$this->classNameInflector->isProxyClassName($className)) {
         return false;
     }
     $file = $this->fileLocator->getProxyFileName($className);
     if (!file_exists($file)) {
         return false;
     }
     /* @noinspection PhpIncludeInspection */
     return (bool) (require_once $file);
 }
 /**
  * Write generated code to disk and return the class code
  *
  * {@inheritDoc}
  */
 public function generate(ClassGenerator $classGenerator)
 {
     $className = trim($classGenerator->getNamespaceName(), '\\') . '\\' . trim($classGenerator->getName(), '\\');
     $generatedCode = $classGenerator->generate();
     $fileName = $this->fileLocator->getProxyFileName($className);
     $tmpFileName = $fileName . '.' . uniqid('', true);
     // renaming files is necessary to avoid race conditions when the same file is written multiple times
     // in a short time period
     file_put_contents($tmpFileName, "<?php\n\n" . $generatedCode);
     rename($tmpFileName, $fileName);
     return $generatedCode;
 }
 /**
  * Write generated code to disk and return the class code
  *
  * {@inheritDoc}
  */
 public function generate(ClassGenerator $classGenerator)
 {
     $className = trim($classGenerator->getNamespaceName(), '\\') . '\\' . trim($classGenerator->getName(), '\\');
     $generatedCode = $classGenerator->generate();
     $fileName = $this->fileLocator->getProxyFileName($className);
     set_error_handler($this->emptyErrorHandler);
     try {
         $this->writeFile("<?php\n\n" . $generatedCode, $fileName);
     } catch (FileNotWritableException $fileNotWritable) {
         restore_error_handler();
         throw $fileNotWritable;
     }
     restore_error_handler();
     return $generatedCode;
 }