2012-04-24 109 views
0

我已經在Symfony2框架內實現了被註釋爲由Doctrine使用的實體。例如:Symfony2中的Doxygen和@ORM註釋實體

/* 
* class description 
* 
* @ORM\Entity(repositoryClass="Website\ContentBundle\Repository\ContentRepository") 
* @ORM\HasLifecycleCallbacks() 
* @ORM\InheritanceType("SINGLE_TABLE") 
* @ORM\DiscriminatorColumn(name="type", type="string") 
* @ORM\DiscriminatorMap({"article" = "Article"}) 
* @ORM\Table(name="content",indexes={@ORM\index(name="id_UNIQUE",columns={"id"})}) 
*/ 
class Content { 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    ... 
    } 

當我在源代碼上運行Doxygen時,文檔的可讀性不是很好。我試圖爲每個@ ORM *符號定義別名;例如「ORM = ORM」,「實體=實體」等等。但這不起作用。對於上述類Doxygen的返回

... 
ORMEntity(repositoryClass="Website\ContentBundle\Repository\ContentRepository") ORM() ORM("SINGLE_TABLE") ORM(name="type", type="string") ORM({"article" = "Article", "picture_series" = "PictureSeries", "event" = "Event", "invitation" = "Invitation"}) ORMTable(name="content",indexes={ORM(name="id_UNIQUE",columns={"id"})}) 

對於方法

/** 
* sets the given id 
* 
* @param number $id 
* @return \Website\ContentBundle\Entity\Content 
*/ 
public function setId($id) { 
    $this->id = $id; 
    return $this; // fluent interface 
} 

Doxygen的創造

setId ($ id)  
    sets the given id 

Parameters: 
    number $id 

Returns: 

爲什麼它沒有顯示後的\網站\的ContentBundle \實體\內容「返回:「?

也許有人可以給我一個提示或鏈接關於如何配置Doxygen,以便它可以適當地處理@ORM註釋。

THX提前!

回答

1

對於這個問題

爲何不顯示Returns:\Website\ContentBundle\Entity\Content

這可能是因爲doxygen的命令與\開始,做的doxygen認爲你在呼喚它不承認一些命令,所以想必從文檔條,不做任何處理。

你是在試圖使用ALIASES配置文件選項的正確方法。但是,您可以使用ORM=\@ORM來代替ORM=ORM。我得到了你的源代碼示例由doxygen的,而不通過如下定義別名的任何警告記錄在案:

ALIASES = "ORM=\@ORM" 
ALIASES += "Entity=\\Entity" 
ALIASES += "InheritanceType=\\InheritanceType" 
ALIASES += "DiscriminatorColumn=\\DiscriminatorColumn" 
ALIASES += "DiscriminatorMap=\\DiscriminatorMap" 
ALIASES += "Table=\\Table" 
ALIASES += "Id=\\Id" 
ALIASES += "Column=\\Column" 
ALIASES += "GeneratedValue=\\GeneratedValue" 
ALIASES += "index=\\index" 
ALIASES += "HasLifecycleCallbacks=\\HasLifecycleCallbacks" 
ALIASES += "Repository=\\Repository" 
ALIASES += "ContentRepository=\\ContentRepository" 
ALIASES += "ContentBundle=\\ContentBundle" 
ALIASES += "Website=\\Website" 
ALIASES += "Content=\\Content" 

這裏\\\@實際上是Doxygen的命令分別打印反斜槓\@字符。

但是請注意,@ORM...指令將全部出現在同一行上。我不知道如何避免這種情況(更新:請參閱下面的我的編輯)。有沒有其他人有任何想法?

最後,作爲一個側面說明,你對$id文件應

* @param $id number 

注意$idnumber的順序。請參閱\param的文檔。

編輯:這樣做會包住主義relavent部分在\verbatim\endverbatim標籤的另一種方法。這將保留類描述中的換行符,這將更具可讀性。

+0

它很好用!關於你如何記錄參數的評論。我選擇了「我的」符號,因爲(1)在Symfony中,幾乎每種方法都以這種方式記錄,(2)在描述參數時它更易讀。我想,@參數$ id數字描述不是那種可讀性。 – LaDude 2012-04-24 11:24:54

+0

很高興我能幫到你。對於習慣於使用「\ param變量」這個概念的人來說,「變量描述」更具可讀性。無論如何,這就是'doramgen'中定義的'\ param' - 所以你使用它是錯誤的,文檔不會反映代碼中實際發生的事情。此外,doxygen會以您的方式發出警告。我強烈建議使用'\ param'在doxygen手冊中如何定義它。 – Chris 2012-04-24 12:01:10

+0

我知道我以某種方式錯誤地使用它。但是,在PHP中,方法的參數列表不顯示每個參數的類型。因此,我認爲,參數類型必須反映在文檔中。 – LaDude 2012-04-24 13:26:10