public static function highlight($code, $language)
{
if ($language !== 'php') {
return htmlspecialchars($code, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
if (strncmp($code, '<?php', 5) === 0) {
$text = @highlight_string(trim($code), true);
} else {
$text = highlight_string("<?php " . trim($code), true);
$text = str_replace('<?php', '', $text);
if (($pos = strpos($text, ' ')) !== false) {
$text = substr($text, 0, $pos) . substr($text, $pos + 6);
}
}
// remove <code><span style="color: #000000">\n and </span>tags added by php
$text = substr(trim($text), 36, -16);
return $text;
}
/** * @param MethodDoc $method * @return string */ public function renderMethodSignature($method, $context = null) { $params = []; foreach ($method->params as $param) { $params[] = (empty($param->typeHint) ? '' : '<span class="signature-type">' . $this->createTypeLink($param->typeHint, $context) . '</span> ') . ($param->isPassedByReference ? '<b>&</b>' : '') . ApiMarkdown::highlight($param->name . ($param->isOptional ? ' = ' . $param->defaultValue : ''), 'php'); } $definition = []; $definition[] = $method->visibility; if ($method->isAbstract) { $definition[] = 'abstract'; } if ($method->isStatic) { $definition[] = 'static'; } return '<span class="signature-defs">' . implode(' ', $definition) . '</span> ' . '<span class="signature-type">' . ($method->isReturnByReference ? '<b>&</b>' : '') . ($method->returnType === null ? 'void' : $this->createTypeLink($method->returnTypes, $context)) . '</span> ' . '<strong>' . $this->createSubjectLink($method, $method->name) . '</strong>' . str_replace(' ', ' ', ' ( ' . implode(', ', $params) . ' )'); }