简体   繁体   English

PHP动态页面级DocBlocks

[英]PHP dynamic Page-level DocBlocks

I was wondering if there is a way to interact with the Page-level DocBlocks. 我想知道是否有一种与页面级DocBlocks交互的方法。 My question is more specifically about wordpress plugin development, but this question has arised also in a non-wordpress environments. 我的问题更具体地是关于wordpress插件开发的,但是在非wordpress环境中也出现了这个问题。

The reason is mainly the possibility to easily change VERSIONS and names throughout a large project with maybe a constant definition - but that will reflect also in the docblock.. 原因主要是可以通过一个恒定的定义轻松地在整个大型项目中更改版本和名称-但这也将反映在docblock中。

The following example Docblock is from a wordpress plugin I write - 以下示例Docblock来自我编写的wordpress插件-

/*
Plugin Name: o99 Auxilary Functions v0.4.7
Plugin URI: http://www.myurl.com
Description: some simple description that nobody reads.
Version: 0.4.7
Author: my cool name
Author URI: http://www.ok-alsouri.com
*/

Is there a way to transform it into : 有没有一种方法可以将其转换为:

$ver = '0.4.7';
$uri = 'http://www.myurl.com';
$desc = 'some simple description that nobody reads.';
$mcn = 'my cool name';
etc.. 
etc..

    /*
    Plugin Name: o99 Auxilary Functions ($ver)
    Plugin URI: ($uri)
    Description: ($desc)
    Version: ($ver)
    Author: ($mcn)
    Author URI: ($$uri)
    */

obviously for echo to work I would need to break the docblock itself, and I can not WRITE the docblock directly into it´s own file . 显然,为了使回显有效,我需要破坏文档块本身,而且我无法将文档块直接写入其自己的文件中。

In shorts : can I "generate" a docblock with php itself somehow (I would think that the answer is - "no" for the page itself.. But maybe I am wrong and someone has some neat hack :-) ) 简而言之:我可以用php本身“生成” docblock吗(我认为答案是-页面本身为“否”。但是也许我是错的,并且有人拥有一些巧妙的技巧:-))

Is that even possible ? 那有可能吗?

You could do: 您可以这样做:

$ver = '0.4.7';
$uri = 'http://www.myurl.com';
$desc = 'some simple description that nobody reads.';
$mcn = 'my cool name';
etc.. 
etc..

$docblock = <<<TEMPLATE
/*
Plugin Name: o99 Auxilary Functions ($ver)
Plugin URI: $uri
Description: $desc
Version: $ver
Author: $mcn
Author URI: $uri
*/
TEMPLATE;

$file_data = $docblock;
$file_data .= file_get_contents('yourplugin.php');
file_put_contents('yourplugin.php', $file_data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM