Попробуйте так (убедитесь что у Вас включен
tokenizer):
<?php
const SCRIPTS_DIR = '/data/www/framework/lib';
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(SCRIPTS_DIR));
$replace = array(
'<hh user=param>' => '#PARAM#',
'<hh user=return>' => '#RETURN#',
'<hh user=desc>' => '#DESC#',
'<hh user=throws>' => '#THROWS#',
'<hh user=see>' => '#SEE#',
'<hh user=link>' => '#LINK#',
'<hh user=access>' => '#ACCESS#',
'<hh user=since>' => '#SINCE#',
'<hh user=static>' => '#STATIC#',
);
foreach($dir as $source) {
if($dir->isDot()) {
continue;
}
$file = file_get_contents($source->getPathname());
$tokens = token_get_all($file);
foreach($tokens as $token) {
if(!is_array($token)) {
continue;
}
if(in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
$text = preg_replace('![\n\r][\t ]*\*!sSim', "\n", $token[1]);
$text = str_replace(array_keys($replace), array_values($replace), $text);
$translate = Yandex::translate($tokens[1]); //
$translate = str_replace(array_values($replace), array_keys($replace), $text);
$file = str_replace($tokens[1], $translate, $file);
}
}
file_put_contents($source->getPathname(), $file);
}