wpdesk / hook-parser

该软件包最新版本(1.5.0)没有可用的许可信息。

WordPress 钩子文档解析器

1.5.0 2021-01-05 13:27 UTC

This package is auto-updated.

Last update: 2024-09-05 22:08:29 UTC


README

一个库,用于解析插件代码以创建钩子文档。

如何文档化

在注释 apply_filterdo_action 函数时使用 PHP Doc 标签。

支持的标签

  • @param
  • @return
  • @see
  • @ignore
  • @internal
  • @since
  • @deprecated

值得关注

  • 解析器可以解析 PHP 代码,因此被注释掉的钩子将被忽略。
  • 代码中的解析错误将阻止成功扫描。
  • 当钩子出现多次时,它将在文档中多次显示。要防止这种情况,请使用 @ignore 标签。

已记录的钩子示例

<?php
/**
 * Do actions when shipment is created via checkout.
 *
 * @param \WPDesk_Flexible_Shipping_Shipment $shipment Created shipment.
 * @see https://flexibleshipping.com/
 * @deprecated
 */
do_action( 'flexible_shipping_checkout_shipment_created', $shipment );
<?php

$some_bool =
    /**
     * Long text.
     * 
     * @param bool $some_bool Some bool value passed to filter.
     * @param string $some_string Some string passed to filter.
     * @return bool Returns true when in a mood. 
     * 
     * @since 1.2.3 
     * @internal Can be changed anytime. 
     */ 
    apply_filters( sprintf( 'some_filter_%s', $var), true, $someothervar );

用法

<?php
$parser       = new \HookParser\CodeParser();
$renderer     = new \HookParser\HtmlRenderer();
$fileIterator = new \HookParser\PHPFileFinder();

$output = '<ul>';
foreach ( $fileIterator->getIterator( 'path/to/plugin/src' ) as $filePath ) {
    foreach ( $parser->parse( file_get_contents( current( $filePath ) ) ) as $hook ) {
        $output .= $renderer->render( $hook );
    }
}

return $output . '</ul>';