public function testCachingFileScannerWillUseSameInternalFileScannerWithMatchingFileNameAnAnnotationManagerObject() { CachingFileScanner::clearCache(); // single entry, based on file $cfs1 = new CachingFileScanner(__DIR__ . '/../TestAsset/BarClass.php'); $this->assertContains('ZendTest\\Code\\TestAsset\\BarClass', $cfs1->getClassNames()); $this->assertEquals(1, $this->getCacheCount($cfs1)); // ensure same class is used internally $cfs2 = new CachingFileScanner(__DIR__ . '/../TestAsset/BarClass.php'); $this->assertEquals(1, $this->getCacheCount($cfs2)); $this->assertSameInternalFileScanner($cfs1, $cfs2); // ensure $cfs3 = new CachingFileScanner(__DIR__ . '/../TestAsset/FooClass.php'); $this->assertEquals(2, $this->getCacheCount($cfs3)); $this->assertDifferentInternalFileScanner($cfs2, $cfs3); $annoManager = new AnnotationManager(); $cfs4 = new CachingFileScanner(__DIR__ . '/../TestAsset/FooClass.php', $annoManager); $this->assertEquals(3, $this->getCacheCount($cfs4)); $this->assertDifferentInternalFileScanner($cfs3, $cfs4); $cfs5 = new CachingFileScanner(__DIR__ . '/../TestAsset/FooClass.php', $annoManager); $this->assertEquals(3, $this->getCacheCount($cfs5)); $this->assertSameInternalFileScanner($cfs4, $cfs5); $cfs6 = new CachingFileScanner(__DIR__ . '/../TestAsset/BarClass.php', $annoManager); $this->assertEquals(4, $this->getCacheCount($cfs6)); $this->assertDifferentInternalFileScanner($cfs5, $cfs6); }
/** * @param \Zend\Code\Annotation\AnnotationManager $annotationManager * @return \Zend\Code\Annotation\AnnotationCollection */ public function getAnnotations(Annotation\AnnotationManager $annotationManager) { if (($docComment = $this->getDocComment()) == '') { return false; } if (!$this->annotations) { $cachingFileScanner = new CachingFileScanner($this->getFileName()); $nameInformation = $cachingFileScanner->getClassNameInformation($this->getDeclaringClass()->getName()); $this->annotations = new AnnotationScanner($annotationManager, $docComment, $nameInformation); } return $this->annotations; }
/** * This method does the work of "reflecting" the file * * Uses Zend\Code\Scanner\FileScanner to gather file information * * @return void */ protected function reflect() { $scanner = new CachingFileScanner($this->filePath); $this->docComment = $scanner->getDocComment(); $this->requiredFiles = $scanner->getIncludes(); $this->classes = $scanner->getClassNames(); $this->namespaces = $scanner->getNamespaces(); $this->uses = $scanner->getUses(); }
/** * Create namespace code * * @param string $namespace * @param Reflection\ClassReflection $class * @return string the namespace + class + uses * @todo Detect defined constants */ protected function buildNamespace(Reflection\ClassReflection $class) { $code = "namespace {$class->getNamespaceName()} {" . PHP_EOL; $uses = array(); // Reformat uses foreach ($class->getDeclaringFile()->getUses() as $use) { $uses[$use['use']] = $use['as']; } //Just sort the uses ksort($uses); // Create block by block $code .= $this->buildUses($uses); // @TODO $this->buildConstants($class); $code .= $this->buildClassDecleration($class); $code .= $this->buildExtend($uses, $class); $code .= $this->buildInterface($uses, $class); $code .= PHP_EOL . $this->buildContent($class) . PHP_EOL; $code .= "}" . PHP_EOL . PHP_EOL; // Clear reflection memory \Zend\Code\Scanner\CachingFileScanner::clearCache(); return fwrite($this->handle, $code); }