/**
* @param Foo $argument
* @see https:/xxxxxxxx/xxxx/xxx.html
*/
function dummy($Foo) {}
/**
* @param Foo $argument
* @see https:/xxxxxxxx/xxxx/xxx.html
*/
function dummy($Foo) {}
$ref = new ReflectionFunction("dummy");
$doc = $ref->getDocComment();
$see = substr($doc, strpos($doc, "@see") + strlen("@see "));
<?php
<<Params("Foo", "argument")>>
<<See("https://xxxxxxxx/xxxx/xxx.html")>>
function dummy($argument) {}
string(3) "See"
array(1) {
[0]=>
string(30) "https://xxxxxxxx/xxxx/xxx.html"
}
<?php
<<phpAttribute>>
class MyAttribute {
public function __construct($name, $value) {
var_dump($name);
var_dumP($value);
}
}
<<MyAttribute("See", "https://xxxxxxxx/xxxx/xxx.html")>>
function dummy($argument) {
}
$ref = new ReflectionFunction("dummy");
$ref->getAttributes("MyAttribute")[0]->newInstance();
<<Name>>然后你就可以通过PHP的Reflection系列的方法,根据getAttributes("Name")获取对应的注解, 进一步你可以通过调用返回的注解的getName方法获取名字,getArguments方法获取括号中的Arguments。
<<Name(Arguments)>>
<<Name(Argunment1, Arguments2, ArgumentN)>>
作者 | 惠新辰(laruence)
来源 | https://www.laruence.com/2020/06/12/5902.html
本文为 @ 21CTO 创作并授权 21CTO 发布,未经许可,请勿转载。
内容授权事宜请您联系 webmaster@21cto.com或关注 21CTO 公众号。
该文观点仅代表作者本人,21CTO 平台仅提供信息存储空间服务。