/** * Generate code to cache from class reflection. * * @todo maybe move some of this into Zend\Code * * @param ClassReflection $classReflection * @return string */ public function getCacheCode(ClassReflection $classReflection) { $useString = $this->fileReflectionService->getUseString($classReflection->getDeclaringFile()); $declaration = $this->classDeclarationService->getClassDeclaration($classReflection); $classContents = $classReflection->getContents(false); $classFileDir = dirname($classReflection->getFileName()); $classContents = trim(str_replace('__DIR__', sprintf("'%s'", $classFileDir), $classContents)); $return = "\nnamespace " . $classReflection->getNamespaceName() . " {\n" . $useString . $declaration . "\n" . $classContents . "\n}\n"; return $return; }
public function testMultipleUseStatements() { $namespace1 = 'All\\The\\Things'; $namespace2 = 'Two\\Namespaces'; $namespace3 = 'One'; $as1 = null; $as2 = ''; $as3 = 'Two'; $expectedUseString = "use {$namespace1};\nuse {$namespace2};\nuse {$namespace3} as {$as3};\n"; Phake::when($this->mockFileReflection)->getUses()->thenReturn(array(array('use' => $namespace1, 'as' => $as1), array('use' => $namespace2, 'as' => $as2), array('use' => $namespace3, 'as' => $as3))); $this->assertEquals($expectedUseString, $this->sut->getUseString($this->mockFileReflection)); }