/** * Export this interface definition to the given parent DOMElement. * * @param \DOMElement $parent Element to augment. * @param InterfaceReflector $interface Element to log export. * @param \DOMElement $child if supplied this element will be * augmented instead of freshly added. * * @return void */ public function export(\DOMElement $parent, $interface, \DOMElement $child = null) { if ($child === null) { $child = new \DOMElement('interface'); $parent->appendChild($child); } $child->setAttribute('namespace', $interface->getNamespace()); $child->setAttribute('line', $interface->getLineNumber()); $short_name = method_exists($interface, 'getShortName') ? $interface->getShortName() : $interface->getName(); $child->appendChild(new \DOMElement('name', $short_name)); $child->appendChild(new \DOMElement('full_name', $interface->getName())); foreach ($interface->getParentInterfaces() as $parent_interface) { $child->appendChild(new \DOMElement('extends', $parent_interface)); } $object = new DocBlockExporter(); $object->export($child, $interface); foreach ($interface->getConstants() as $constant) { $object = new ConstantExporter(); $constant->setDefaultPackageName($interface->getDefaultPackageName()); $object->export($child, $constant); } foreach ($interface->getProperties() as $property) { $object = new PropertyExporter(); $property->setDefaultPackageName($interface->getDefaultPackageName()); $object->export($child, $property); } foreach ($interface->getMethods() as $method) { $object = new MethodExporter(); $method->setDefaultPackageName($interface->getDefaultPackageName()); $object->export($child, $method); } }
public function parseSubElements() { /** @var \PHPParser_Node_Stmt_TraitUse $stmt */ foreach ($this->node->stmts as $stmt) { if ($stmt instanceof \PHPParser_Node_Stmt_TraitUse) { foreach ($stmt->traits as $trait) { $this->traits[] = '\\' . (string) $trait; } } } parent::parseSubElements(); }
private function registerReflectors(InterfaceReflector $reflector) { if (!$this->reflector) { $this->reflector = $reflector; } $loader = $this->autoLoader; /** * @var $method MethodReflector */ $reflector->getName(); foreach ($reflector->getMethods() as $method) { $this->data['methods'][$method->getShortName()][] = $method; } if ($reflector instanceof ClassReflector || $reflector instanceof TraitReflector) { if ($parent = $reflector->getParentClass()) { $filename = $loader($parent); if (is_readable($filename)) { $parser = $this->parserFactory->newInstance($filename, $loader); $this->data = array_merge_recursive($this->data, $parser->getData()); } } if ($traits = $reflector->getTraits()) { foreach ($traits as $trait) { $filename = $loader($trait); if (is_readable($filename)) { $parser = $this->parserFactory->newInstance($filename, $loader); $this->data = array_merge_recursive($this->data, $parser->getData()); } } } } if (method_exists($reflector, 'getInterfaces')) { foreach ($reflector->getInterfaces() as $interface) { $filename = $loader($interface); if (is_readable($filename)) { $parser = $this->parserFactory->newInstance($filename, $loader); $this->data = array_merge_recursive($this->data, $parser->getData()); } } } }
/** * Creates a Descriptor from the provided data. * * @param InterfaceReflector $data * * @return InterfaceDescriptor */ public function create($data) { $interfaceDescriptor = new InterfaceDescriptor(); $interfaceDescriptor->setFullyQualifiedStructuralElementName($data->getName()); $interfaceDescriptor->setName($data->getShortName()); $interfaceDescriptor->setLine($data->getLinenumber()); $interfaceDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: ''); // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself $interfaceDescriptor->setNamespace('\\' . (strtolower($data->getNamespace()) == 'global' ? '' : $data->getNamespace())); $this->assembleDocBlock($data->getDocBlock(), $interfaceDescriptor); $this->addConstants($data->getConstants(), $interfaceDescriptor); $this->addMethods($data->getMethods(), $interfaceDescriptor); foreach ($data->getParentInterfaces() as $interfaceClassName) { $interfaceDescriptor->getParent()->set($interfaceClassName, $interfaceClassName); } return $interfaceDescriptor; }
public function enterNode(PHPParser_Node $node) { $prettyPrinter = new PHPParser_PrettyPrinter_Zend(); switch (get_class($node)) { case 'PHPParser_Node_Stmt_Use': /** @var PHPParser_Node_Stmt_UseUse $use */ foreach ($node->uses as $use) { $this->context->setNamespaceAlias($use->alias, implode('\\', $use->name->parts)); } break; case 'PHPParser_Node_Stmt_Namespace': $this->context->setNamespace(implode('\\', $node->name->parts)); break; case 'PHPParser_Node_Stmt_Class': $class = new ClassReflector($node, $this->context); $class->parseSubElements(); $this->classes[] = $class; break; case 'PHPParser_Node_Stmt_Trait': $trait = new TraitReflector($node, $this->context); $this->traits[] = $trait; break; case 'PHPParser_Node_Stmt_Interface': $interface = new InterfaceReflector($node, $this->context); $interface->parseSubElements(); $this->interfaces[] = $interface; break; case 'PHPParser_Node_Stmt_Function': $function = new FunctionReflector($node, $this->context); $this->functions[] = $function; break; case 'PHPParser_Node_Stmt_Const': foreach ($node->consts as $constant) { $reflector = new ConstantReflector($node, $this->context, $constant); $this->constants[] = $reflector; } break; case 'PHPParser_Node_Expr_FuncCall': if ($node->name instanceof PHPParser_Node_Name && $node->name == 'define') { $name = trim($prettyPrinter->prettyPrintExpr($node->args[0]->value), '\''); $constant = new PHPParser_Node_Const($name, $node->args[1]->value, $node->getAttributes()); $constant->namespacedName = new PHPParser_Node_Name(($this->current_namespace ? $this->current_namespace . '\\' : '') . $name); $reflector = new ConstantReflector(new \PHPParser_Node_Stmt_Const(array($constant)), $this->context, $constant); $this->constants[] = $reflector; } break; case 'PHPParser_Node_Expr_Include': $include = new IncludeReflector($node, $this->context); $this->includes[] = $include; break; } }
public function leaveNode(PHPParser_Node $node) { $prettyPrinter = new PrettyPrinter(); switch (get_class($node)) { case 'PHPParser_Node_Stmt_Use': /** @var PHPParser_Node_Stmt_UseUse $use */ foreach ($node->uses as $use) { $this->context->setNamespaceAlias($use->alias, implode('\\', $use->name->parts)); } break; case 'PHPParser_Node_Stmt_Namespace': $this->context->setNamespace(isset($node->name) && $node->name ? implode('\\', $node->name->parts) : ''); break; case 'PHPParser_Node_Stmt_Class': $class = new ClassReflector($node, $this->context); $class->parseSubElements(); $this->classes[] = $class; break; case 'PHPParser_Node_Stmt_Trait': $trait = new TraitReflector($node, $this->context); $trait->parseSubElements(); $this->traits[] = $trait; break; case 'PHPParser_Node_Stmt_Interface': $interface = new InterfaceReflector($node, $this->context); $interface->parseSubElements(); $this->interfaces[] = $interface; break; case 'PHPParser_Node_Stmt_Function': $function = new FunctionReflector($node, $this->context); $this->functions[] = $function; break; case 'PHPParser_Node_Stmt_Const': foreach ($node->consts as $constant) { $reflector = new ConstantReflector($node, $this->context, $constant); $this->constants[] = $reflector; } break; case 'PHPParser_Node_Expr_FuncCall': if ($node->name instanceof PHPParser_Node_Name && $node->name == 'define' && isset($node->args[0]) && isset($node->args[1])) { // transform the first argument of the define function call into a constant name $name = str_replace(array('\\\\', '"', "'"), array('\\', '', ''), trim($prettyPrinter->prettyPrintExpr($node->args[0]->value), '\'')); $nameParts = explode('\\', $name); $shortName = end($nameParts); $constant = new PHPParser_Node_Const($shortName, $node->args[1]->value, $node->getAttributes()); $constant->namespacedName = new PHPParser_Node_Name($name); $constant_statement = new \PHPParser_Node_Stmt_Const(array($constant)); $constant_statement->setAttribute('comments', array($node->getDocComment())); $this->constants[] = new ConstantReflector($constant_statement, $this->context, $constant); } break; case 'PHPParser_Node_Expr_Include': $include = new IncludeReflector($node, $this->context); $this->includes[] = $include; break; } }