Commit cf0d582a by Brandon Kelly Committed by Alexander Makarov

Added yii\web\ErrorHandler::getTypeUrl()

Makes it possible for classes that extend yii\web\ErrorHandler to provide their own informational URLs for types/classes/methods.
parent a6dd9d37
...@@ -173,20 +173,39 @@ class ErrorHandler extends \yii\base\ErrorHandler ...@@ -173,20 +173,39 @@ class ErrorHandler extends \yii\base\ErrorHandler
$text = $this->htmlEncode($class) . '::' . $this->htmlEncode($method); $text = $this->htmlEncode($class) . '::' . $this->htmlEncode($method);
} else { } else {
$class = $code; $class = $code;
$method = null;
$text = $this->htmlEncode($class); $text = $this->htmlEncode($class);
} }
if (strpos($code, 'yii\\') !== 0) { $url = $this->getTypeUrl($class, $method);
if (!$url) {
return $text; return $text;
} }
return '<a href="' . $url . '" target="_blank">' . $text . '</a>';
}
/**
* Returns the informational link URL for a given PHP type/class.
* @param string $class the type or class name.
* @param string|null $method the method name.
* @return string|null the informational link URL.
* @see addTypeLinks()
*/
protected function getTypeUrl($class, $method)
{
if (strpos($class, 'yii\\') !== 0) {
return null;
}
$page = $this->htmlEncode(strtolower(str_replace('\\', '-', $class))); $page = $this->htmlEncode(strtolower(str_replace('\\', '-', $class)));
$url = "http://www.yiiframework.com/doc-2.0/$page.html"; $url = "http://www.yiiframework.com/doc-2.0/$page.html";
if (isset($method)) { if ($method) {
$url .= "#$method()-detail"; $url .= "#$method()-detail";
} }
return '<a href="' . $url . '" target="_blank">' . $text . '</a>'; return $url;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment