基本的に、私はdocblockでカスタム注釈を読んでいます
/**
* This exception is thrown when no constant function is found.
*
* @author Time.ly Network Inc.
* @since 2.0
*
* @instantiator Ai1ec_View_Factory Category_Exception
* @package AI1EC
* @subpackage AI1EC.Config
*/
class Ai1ec_Constants_Not_Set_Exception extends Ai1ec_Exception {
}
私はdocblockを取得してから、注釈を取得しようとします
$r = new ReflectionClass($tokens[$i][1]);
$doc = $r->getDocComment();
preg_match_all('#^.*.@instantiator\s+(.*?)\n#s', $doc, $annotations);
これは実際には機能していますが、最適ではありません。私は試した
preg_match_all('#^\s\\*\s?@instantiator\s+(.*?)\n#s', $doc, $annotations);
1 つのスペース、星、ゼロまたは 1 つのスペース @instantiator 1 つまたは複数のスペースに一致し、行末まで何かを取得しますが、機能せず、一致しません。また、正規表現の行末にある最終的な空白をどのように削除できますか?