phpDocumentor學習使用記錄

來源:互聯網
上載者:User
phpDocumentor學習使用記錄

一.phpDocumentor簡介

PHPDocumentor是一個用PHP寫的工具,對於有規範注釋的php程式,它能夠快速產生具有相互參照,索引等功能的API文檔。老的版本是phpdoc,從1.3.0開始,更名為phpDocumentor,新的版本加上了對php5文法的支援,同時,可以通過在用戶端瀏覽器上操作產生文檔,文檔可以轉換為PDF,HTML,CHM幾種形式,非常的方便。

phpDocumentor是一個非常強大的文檔自動產生工具,利用它可以協助我們編寫規範的注釋,產生易於理解,結構清晰的文檔,對我們的代碼升級,維護,移交等都有非常大的協助。

二.那些元素可以產生文檔

Function 函數

Constant 常量

Class 類

Interface 介面

Trait 特性

Class constant 類常量

Property 屬性

Method 方法

File 檔案

include/require聲明 包含檔案聲明

Variable 變數

三.基本格式

1.Summary 總結

2.Description 詳細描述

3.Tags and annotations 標籤和注釋

Example:

/**

* 函數add,實現兩個數的加法

*

* 一個簡單的加法計算,函數接受兩個數a、b,返回他們的和c

*

* @param int 加數

* @param int 被加數

* @return integer 傳回值

*

*/

function Add($a, $b)

{

return $a+$b;

}

?>

用命令 phpdoc -d 項目絕對路徑 -t 產生的文檔存放的路徑 產生文檔

如下:

Add

integer Add( int $a, int $b)

[line 45]

函數add,實現兩個數的加法

Constants 一個簡單的加法計算,函數接受兩個數a、b,返回他們的和c

Parameters

・ int $a - 加數

・ int $b - 被加數

四.標籤詳細list

Tag

Element

Description

api

Method

用來聲明一個結構元素是否可被用作第三方API

author

Any

建立者資訊

category

File、class

檔案或者類所屬的目錄

copyright

Any

著作權資訊

deprecated

Any

此tag將在將來的版本中被棄用

example

Any

這個tag指明範例程式碼的路徑

filesource

File

源檔案輸出

global

Variable

全域變數

ignore

Any

這個標籤不會包括在文檔中

internal

Any

這個標籤僅在應用程式和內部庫使用

license

File, Class

檔案和類的許可證資訊

link

Any

指明元素和網站的連結關係

method

Class

指明類可用的魔術方法

package

File, Class

檔案和類所屬的包資訊

param

Method,Function

方法和函數的參數資訊

property

Class

類的屬性資訊

property-read

Class

類的唯讀屬性資訊

property-write

Class

類的唯寫屬性資訊

return

Method,Function

方法和函數的傳回值

see

Any

指明參考引用出處

since

Any

元素從那個版本起用

source

Any, except File

顯示元素的原始碼

subpackage

File, Class

指明類和檔案的子包

throws

Method,Function

指明元素可能拋出的異常

todo

Any

指明這個元素正在開發中

uses

Any

指明元素引用的其他元素

var

Properties

指明類的屬性

version

Any

指明當前元素的版本

五.類型

目前phpDocumentor中元素的各種標籤需要和支援的各種類型。

1. 完整類名或者別名

使用它的完全限定類名(FQCN),這意味著類有一個首碼斜線,以表明它是類,如全名 \phpDocumentor\Descriptor\ClassDescriptor。

使用相對類名,例如 \Descriptor\ClassDescriptor。

用類的別名,例如 use phpDocumentorDescriptorParamDescriptor as Param

2. Php關鍵字

string

int or integer

float

bool or boolean

array

resource

null

callable

3. Phpdoc標準的關鍵字

mixed

void

object

false or true

self

static

$this

4. 等位型別

/** @return string|null */

六.運行phpDocumentor

Phpdoc

phpdoc run

phpdoc project:run

上面三個可以實現相同效果。

參數:

-d 項目源檔案路徑

-f 制定項目某一個檔案

-t 產生文檔的目錄

phpdoc -d path/to/my/project -f path/to/an/additional/file -t path/to/my/output/folder

七.標籤格式

1.@api

格式:@api

例如:

/**

*

* @api

*

*/

2. @author

格式:@author [name] []

例如:

/**
     * @author My Name
     * @author My Name 
     */

3. @category

格式:@category [description]
例如:
/**
      * @category MyCategory
      */

4. @copyright

格式:@copyright [description]
例如:
/**
      * @copyright 1997-2005 The PHP Group
      */

5. @deprecated

格式:@deprecated [] []

例如:

/**
     * @deprecated
     * @deprecated 1.0.0
     * @deprecated No longer used by internal code and not recommended.
     * @deprecated 1.0.0 No longer used by internal code and not recommended.
     */

6. @example

格式:@example [location] [ [] ] []

例如:

   /**
     * @example example1.php Counting in action.
     * @example http://example.com/example2.phps Counting in action by a 3rd party.
     * @example "My Own Example.php" My counting.
     */

7. @filesource

格式:@filesource

例如:

    /**
      * @filesource
      */

8. @global

格式:@global [Type] [name] @global [Type] [description]

例如:

    /**
      * @global string $user
      * @global string username
      */

9. @ignore

格式:@ignore []

例如:

     /**
      * @ignore
      */

10. @internal

格式:@internal [description]

例如:

      /**
        * @internal
        */

11. @license

格式:@license [] [name]

例如:

     /**
       * @license GPL
       * @license http://opensource.org/licenses/gpl-license.php GNU Public License
       */

12.@link

格式:@link [URI] []

{@link [URI] []}

例如:

      /**
        * @link http://example.com/my/bar Documentation of Foo.
        * When no more Foo ({@link http://example.com/my/bar}) are given 
        * this function will add one as there must always be one Foo.
        */

13. @method

格式:@method [return type] [name]([[type] [parameter]<, ...>]) []

例如:

      /**
        * @method string getString()
        * @method void setInteger(integer $integer)
        * @method setString(integer $integer)
        */

14. @package

格式:@package [level 1]\[level 2]\[etc.]

例如:

      /**
        * @package PSR\Documentation\API
        */

15. @param

格式:@param [Type] [name] []

例如:

      /**
        * @param mixed[] $items Array structure to count the elements of.
        */

16.@property

格式:@property [Type] [name] []

例如:

       /**
         * @property string $myProperty
         */

17. @property-read

格式:@property-read [Type] [name] [

       例如:
/**
         * @property-read string $myProperty
         */

18. @property-write

格式:@property-write [Type] [name] []

例如:

      /**
        * @property-write string $myProperty
        */

19.@return

格式:@return [Type] []

例如:

       /**
         * @return integer Indicates the number of items.
         * @return string|null The label's text or null if none provided.
         */

20. @see

格式:@see [URI | FQSEN] []

例如:

      /**
        * @see http://example.com/my/bar Documentation of Foo.
        * @see MyClass::$items For the property whose items are counted.
        * @see MyClass::setItems() To set the items for this collection.
        */

21. @since

格式:@since [version] []

例如:

    /**
      * @since 1.0.2 Added the $b argument.
      * @since 1.0.1 Added the $a argument.
      * @since 1.0.0
      *
      */
      function dump($a, $b)
      {
          <...>
      }

22. @source

格式:@source [ [] ] []

例如:

    /**
      * @source 2 1 Check that ensures lazy counting.
      */

23. @subpackage

格式:@subpackage [name]

例如:

    /**
      * @package PSR
      * @subpackage Documentation\API
      */

24. @throws

格式:@throws [Type] []

例如:

    /**
      * @throws InvalidArgumentException if the provided argument is not 
      *  of type 'array'.
      */

25. @todo

格式:@todo [description]

例如:

    /**
      * @todo add an array parameter to count
  */

26. @uses

格式:@uses [FQSEN] []

例如:

    /**
      * @uses MyClass::$items to retrieve the count from.
     */

27. @var

格式:@var [“Type”] [$element_name] []

例如:

    /** @var string|null Should contain a description
      * @var string $name        Should contain a description
      * @var string $description Should contain a description
      */

28. @version

格式:@version [] []

    /**
      * @version 1.0.1
      * @version GIT: $Id$ In development. Very unstable.
      */
 
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.