搜索
首页后端开发php教程phpDocumentor学习使用记录

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 <my.name@example.com>
     */

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.
      */
 

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
您如何防止与会议有关的跨站点脚本(XSS)攻击?您如何防止与会议有关的跨站点脚本(XSS)攻击?Apr 23, 2025 am 12:16 AM

要保护应用免受与会话相关的XSS攻击,需采取以下措施:1.设置HttpOnly和Secure标志保护会话cookie。2.对所有用户输入进行输出编码。3.实施内容安全策略(CSP)限制脚本来源。通过这些策略,可以有效防护会话相关的XSS攻击,确保用户数据安全。

您如何优化PHP会话性能?您如何优化PHP会话性能?Apr 23, 2025 am 12:13 AM

优化PHP会话性能的方法包括:1.延迟会话启动,2.使用数据库存储会话,3.压缩会话数据,4.管理会话生命周期,5.实现会话共享。这些策略能显着提升应用在高并发环境下的效率。

什么是session.gc_maxlifetime配置设置?什么是session.gc_maxlifetime配置设置?Apr 23, 2025 am 12:10 AM

thesession.gc_maxlifetimesettinginphpdeterminesthelifespanofsessiondata,setInSeconds.1)它'sconfiguredinphp.iniorviaini_set().2)abalanceIsiseededeedeedeedeedeedeedto to to avoidperformance andununununununexpectedLogOgouts.3)

您如何在PHP中配置会话名?您如何在PHP中配置会话名?Apr 23, 2025 am 12:08 AM

在PHP中,可以使用session_name()函数配置会话名称。具体步骤如下:1.使用session_name()函数设置会话名称,例如session_name("my_session")。2.在设置会话名称后,调用session_start()启动会话。配置会话名称可以避免多应用间的会话数据冲突,并增强安全性,但需注意会话名称的唯一性、安全性、长度和设置时机。

您应该多久再生一次会话ID?您应该多久再生一次会话ID?Apr 23, 2025 am 12:03 AM

会话ID应在登录时、敏感操作前和每30分钟定期重新生成。1.登录时重新生成会话ID可防会话固定攻击。2.敏感操作前重新生成提高安全性。3.定期重新生成降低长期利用风险,但需权衡用户体验。

如何在PHP中设置会话cookie参数?如何在PHP中设置会话cookie参数?Apr 22, 2025 pm 05:33 PM

在PHP中设置会话cookie参数可以通过session_set_cookie_params()函数实现。1)使用该函数设置参数,如过期时间、路径、域名、安全标志等;2)调用session_start()使参数生效;3)根据需求动态调整参数,如用户登录状态;4)注意设置secure和httponly标志以提升安全性。

在PHP中使用会议的主要目的是什么?在PHP中使用会议的主要目的是什么?Apr 22, 2025 pm 05:25 PM

在PHP中使用会话的主要目的是维护用户在不同页面之间的状态。1)会话通过session_start()函数启动,创建唯一会话ID并存储在用户cookie中。2)会话数据保存在服务器上,允许在不同请求间传递数据,如登录状态和购物车内容。

您如何在子域中分享会议?您如何在子域中分享会议?Apr 22, 2025 pm 05:21 PM

如何在子域名间共享会话?通过设置通用域名的会话cookie实现。1.在服务器端设置会话cookie的域为.example.com。2.选择合适的会话存储方式,如内存、数据库或分布式缓存。3.通过cookie传递会话ID,服务器根据ID检索和更新会话数据。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版