diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 22e34ad..a4b02af 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -179,16 +179,29 @@ class ApiDocExtractor */ protected function getData(ApiDoc $annotation, Route $route, \ReflectionMethod $method) { + $docblock = $this->getDocComment($method); + if (null === $annotation->getDescription()) { - $comments = explode("\n @", $this->getDocComment($method)); + $comments = explode("\n @", $docblock); // just set the first line $comment = trim($comments[0]); $comment = preg_replace("#[\n]+#", ' ', $comment); $comment = preg_replace('#[ ]+#', ' ', $comment); - $annotation->setDescription($comment); + if ('@' !== substr($comment, 0, 1)) { + $annotation->setDescription($comment); + } } + $paramDocs = array(); + foreach (explode("\n", $docblock) as $line) { + if (preg_match('{^@param (.+)}', trim($line), $matches)) { + $paramDocs[] = $matches[1]; + } + } + + $route->addOptions(array('_paramDocs' => $paramDocs)); + return array('annotation' => $annotation, 'route' => $route); } diff --git a/Formatter/AbstractFormatter.php b/Formatter/AbstractFormatter.php index 9ad7a0f..0784bca 100644 --- a/Formatter/AbstractFormatter.php +++ b/Formatter/AbstractFormatter.php @@ -78,12 +78,46 @@ abstract class AbstractFormatter implements FormatterInterface { $method = $route->getRequirement('_method'); $data = array( - 'method' => $method ?: 'ANY', - 'uri' => $route->compile()->getPattern(), - 'requirements' => $route->compile()->getRequirements(), + 'method' => $method ?: 'ANY', + 'uri' => $route->compile()->getPattern(), ); - unset($data['requirements']['_method']); + $requirements = array(); + foreach ($route->compile()->getRequirements() as $name => $value) { + if ('_method' !== $name) { + $requirements[$name] = array( + 'value' => $value, + 'type' => '', + 'description' => '', + ); + } + } + + if (null !== $paramDocs = $route->getOption('_paramDocs')) { + $regexp = '{(\w*) *\$%s +(.*)}i'; + foreach ($route->compile()->getVariables() as $var) { + $found = false; + foreach ($paramDocs as $paramDoc) { + if (preg_match(sprintf($regexp, preg_quote($var)), $paramDoc, $matches)) { + $requirements[$var]['type'] = isset($matches[1]) ? $matches[1] : ''; + $requirements[$var]['description'] = $matches[2]; + + if (!isset($requirements[$var]['value'])) { + $requirements[$var]['value'] = ''; + } + + $found = true; + break; + } + } + + if (!isset($requirements[$var]) && false === $found) { + $requirements[$var] = array('value' => '', 'type' => '', 'description' => ''); + } + } + } + + $data['requirements'] = $requirements; if (null !== $formType = $apiDoc->getFormType()) { $data['parameters'] = $this->parser->parse(new $formType()); diff --git a/Formatter/MarkdownFormatter.php b/Formatter/MarkdownFormatter.php index 15c50a5..3cb42da 100644 --- a/Formatter/MarkdownFormatter.php +++ b/Formatter/MarkdownFormatter.php @@ -29,8 +29,19 @@ class MarkdownFormatter extends AbstractFormatter if (isset($data['requirements']) && !empty($data['requirements'])) { $markdown .= "#### Requirements ####\n\n"; - foreach ($data['requirements'] as $name => $value) { - $markdown .= sprintf("* %s: %s\n", $name, $value); + foreach ($data['requirements'] as $name => $infos) { + $markdown .= sprintf("**%s**\n\n", $name); + + if (!empty($infos['value'])) { + $markdown .= sprintf(" - Value: %s\n", $infos['value']); + } + + if (!empty($infos['type'])) { + $markdown .= sprintf(" - Type: %s\n", $infos['type']); + } + if (!empty($infos['description'])) { + $markdown .= sprintf(" - Description: %s\n", $infos['description']); + } } $markdown .= "\n"; diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig index 40e80b8..c3860a3 100644 --- a/Resources/views/method.html.twig +++ b/Resources/views/method.html.twig @@ -22,13 +22,17 @@