/** * @group ZF-7909 */ public function testClassFromReflectionDiscardParentImplementedInterfaces() { $reflClass = new Reflection\ReflectionClass('\\ZendTest\\CodeGenerator\\PHP\\TestAsset\\NewClassWithInterface'); $codeGen = PHP\PHPClass::fromReflection($reflClass); $codeGen->setSourceDirty(true); $code = $codeGen->generate(); $expectedClassDef = 'class NewClassWithInterface extends ClassWithInterface implements ThreeInterface'; $this->assertContains($expectedClassDef, $code); }
/** * fromReflection() * * @param \Zend\Reflection\ReflectionFile $reflectionFile * @return \Zend\CodeGenerator\PHP\PHPFile */ public static function fromReflection(Reflection\ReflectionFile $reflectionFile) { $file = new self(); $file->setSourceContent($reflectionFile->getContents()); $file->setSourceDirty(false); $body = $reflectionFile->getContents(); // @todo this whole area needs to be reworked with respect to how body lines are processed foreach ($reflectionFile->getClasses() as $class) { $phpClass = PHPClass::fromReflection($class); $phpClass->setPHPFile($file); $file->setClass($phpClass); $classStartLine = $class->getStartLine(true); $classEndLine = $class->getEndLine(); $bodyLines = explode("\n", $body); $bodyReturn = array(); for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) { if ($lineNum == $classStartLine) { $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerClass); //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */'; $lineNum = $classEndLine; } else { $bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion } } $body = implode("\n", $bodyReturn); unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine); } $namespace = $reflectionFile->getNamespace(); if ($namespace != '') { $file->setNamespace($reflectionFile->getNamespace()); } $uses = $reflectionFile->getUses(); if ($uses) { $file->setUses($uses); } if ($reflectionFile->getDocComment() != '') { $docblock = $reflectionFile->getDocblock(); $file->setDocblock(PHPDocblock::fromReflection($docblock)); $bodyLines = explode("\n", $body); $bodyReturn = array(); for ($lineNum = 1; $lineNum <= count($bodyLines); $lineNum++) { if ($lineNum == $docblock->getStartLine()) { $bodyReturn[] = str_replace('?', $class->getName(), self::$_markerDocblock); //'/* Zend_CodeGenerator_Php_File-ClassMarker: {' . $class->getName() . '} */'; $lineNum = $docblock->getEndLine(); } else { $bodyReturn[] = $bodyLines[$lineNum - 1]; // adjust for index -> line conversion } } $body = implode("\n", $bodyReturn); unset($bodyLines, $bodyReturn, $classStartLine, $classEndLine); } $file->setBody($body); return $file; }