Ejemplo n.º 1
0
 /**
  * fromReflectedFilePath() - use this if you intend on generating code generation objects based on the same file.
  * This will keep previous changes to the file in tact during the same PHP process
  *
  * @param string $filePath
  * @param bool $usePreviousCodeGeneratorIfItExists
  * @param bool $includeIfNotAlreadyIncluded
  * @return \Zend\CodeGenerator\Php\PhpFile
  */
 public static function fromReflectedFileName($filePath, $usePreviousCodeGeneratorIfItExists = true, $includeIfNotAlreadyIncluded = true)
 {
     $realpath = realpath($filePath);
     if ($realpath === false) {
         if (($realpath = Reflection\file::findRealpathInIncludePath($filePath)) === false) {
             throw new Exception\InvalidArgumentException('No file for ' . $realpath . ' was found.');
         }
     }
     if ($usePreviousCodeGeneratorIfItExists && isset(self::$_fileCodeGenerators[$realpath])) {
         return self::$_fileCodeGenerators[$realpath];
     }
     if ($includeIfNotAlreadyIncluded && !in_array($realpath, get_included_files())) {
         include $realpath;
     }
     $codeGenerator = self::fromReflection($fileReflector = new Reflection\ReflectionFile($realpath));
     if (!isset(self::$_fileCodeGenerators[$fileReflector->getFileName()])) {
         self::$_fileCodeGenerators[$fileReflector->getFileName()] = $codeGenerator;
     }
     return $codeGenerator;
 }
Ejemplo n.º 2
0
 public function testFileGetFilenameReturnsCorrectFilename()
 {
     require_once 'Zend/Version.php';
     $reflectionFile = new Reflection\ReflectionFile('Zend/Version.php');
     // Make sure this test works on all platforms
     $this->assertRegExp('#^.*Zend.Version.php$#i', $reflectionFile->getFileName());
 }