From a1517543e86fe85490f880ac79b03df02d8fce34 Mon Sep 17 00:00:00 2001
From: Vincent CHALAMON <vincentchalamon@gmail.com>
Date: Fri, 16 Aug 2013 19:18:05 +0200
Subject: [PATCH] Enable PHPDoc @link feature

---
 Annotation/ApiDoc.php            | 17 +++++++++++++++++
 Extractor/ApiDocExtractor.php    |  3 +++
 Resources/views/method.html.twig |  5 +++++
 3 files changed, 25 insertions(+)

diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php
index 9b22792..793e6ef 100644
--- a/Annotation/ApiDoc.php
+++ b/Annotation/ApiDoc.php
@@ -49,6 +49,11 @@ class ApiDoc
      */
     private $output = null;
 
+    /**
+     * @var string
+     */
+    private $link = null;
+
     /**
      * Most of the time, a single line of text describing the action.
      *
@@ -242,6 +247,14 @@ class ApiDoc
         $this->description = $description;
     }
 
+    /**
+     * @param string $link
+     */
+    public function setLink($link)
+    {
+        $this->link = $link;
+    }
+
     /**
      * @param string $section
      */
@@ -441,6 +454,10 @@ class ApiDoc
             $data['description'] = $description;
         }
 
+        if ($link = $this->link) {
+            $data['link'] = $link;
+        }
+
         if ($documentation = $this->documentation) {
             $data['documentation'] = $documentation;
         }
diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php
index 7277732..3eb69d9 100644
--- a/Extractor/ApiDocExtractor.php
+++ b/Extractor/ApiDocExtractor.php
@@ -337,6 +337,9 @@ class ApiDocExtractor
             if (preg_match('{^@deprecated\b(.*)}', trim($line), $matches)) {
                 $annotation->setDeprecated(true);
             }
+            if (preg_match('{^@link\b(.*)}', trim($line), $matches)) {
+                $annotation->setLink($matches[1]);
+            }
         }
 
         $regexp = '{(\w*) *\$%s\b *(.*)}i';
diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig
index ed7c31b..de96986 100644
--- a/Resources/views/method.html.twig
+++ b/Resources/views/method.html.twig
@@ -48,6 +48,11 @@
                 <div>{{ data.documentation|extra_markdown }}</div>
             {% endif %}
 
+            {% if data.link is defined and data.link is not empty %}
+                <h4>Link</h4>
+                <div><a href="{{ data.link }}" target="_blank">{{ data.link }}</a></div>
+            {% endif %}
+
             {% if data.requirements is defined  and data.requirements is not empty %}
                 <h4>Requirements</h4>
                 <table class="fullwidth">