yii\apidoc\helpers\ApiMarkdown::highlight PHP Method

highlight() public static method

Highlights code
Deprecation: since 2.0.5 this method is not used anymore, highlight.php is used for highlighting
public static highlight ( string $code, string $language ) : string
$code string code to highlight
$language string language of the code to highlight
return string HTML of highlighted code
    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('&lt;?php', '', $text);
            if (($pos = strpos($text, '&nbsp;')) !== 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;
    }

Usage Example

Beispiel #1
0
 /**
  * @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) . ' )');
 }
All Usage Examples Of yii\apidoc\helpers\ApiMarkdown::highlight