選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Panel.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\debug;
  8. use Yii;
  9. use yii\base\Component;
  10. use yii\helpers\ArrayHelper;
  11. use yii\helpers\Url;
  12. /**
  13. * Panel is a base class for debugger panel classes. It defines how data should be collected,
  14. * what should be displayed at debug toolbar and on debugger details view.
  15. *
  16. * @property string $detail Content that is displayed in debugger detail view. This property is read-only.
  17. * @property string $name Name of the panel. This property is read-only.
  18. * @property string $summary Content that is displayed at debug toolbar. This property is read-only.
  19. * @property string $url URL pointing to panel detail view. This property is read-only.
  20. *
  21. * @author Qiang Xue <qiang.xue@gmail.com>
  22. * @since 2.0
  23. */
  24. class Panel extends Component
  25. {
  26. /**
  27. * @var string panel unique identifier.
  28. * It is set automatically by the container module.
  29. */
  30. public $id;
  31. /**
  32. * @var string request data set identifier.
  33. */
  34. public $tag;
  35. /**
  36. * @var Module
  37. */
  38. public $module;
  39. /**
  40. * @var mixed data associated with panel
  41. */
  42. public $data;
  43. /**
  44. * @var array array of actions to add to the debug modules default controller.
  45. * This array will be merged with all other panels actions property.
  46. * See [[\yii\base\Controller::actions()]] for the format.
  47. */
  48. public $actions = [];
  49. /**
  50. * @return string name of the panel
  51. */
  52. public function getName()
  53. {
  54. return '';
  55. }
  56. /**
  57. * @return string content that is displayed at debug toolbar
  58. */
  59. public function getSummary()
  60. {
  61. return '';
  62. }
  63. /**
  64. * @return string content that is displayed in debugger detail view
  65. */
  66. public function getDetail()
  67. {
  68. return '';
  69. }
  70. /**
  71. * Saves data to be later used in debugger detail view.
  72. * This method is called on every page where debugger is enabled.
  73. *
  74. * @return mixed data to be saved
  75. */
  76. public function save()
  77. {
  78. return null;
  79. }
  80. /**
  81. * Loads data into the panel
  82. *
  83. * @param mixed $data
  84. */
  85. public function load($data)
  86. {
  87. $this->data = $data;
  88. }
  89. /**
  90. * @param null|array $additionalParams Optional additional parameters to add to the route
  91. * @return string URL pointing to panel detail view
  92. */
  93. public function getUrl($additionalParams = null)
  94. {
  95. $route = [
  96. '/' . $this->module->id . '/default/view',
  97. 'panel' => $this->id,
  98. 'tag' => $this->tag,
  99. ];
  100. if (is_array($additionalParams)){
  101. $route = ArrayHelper::merge($route, $additionalParams);
  102. }
  103. return Url::toRoute($route);
  104. }
  105. /**
  106. * Returns a trace line
  107. * @param array $options The array with trace
  108. * @return string the trace line
  109. * @since 2.0.7
  110. */
  111. public function getTraceLine($options)
  112. {
  113. if (!isset($options['text'])) {
  114. $options['text'] = "{$options['file']}:{$options['line']}";
  115. }
  116. $traceLine = $this->module->traceLine;
  117. if ($traceLine === false) {
  118. return $options['text'];
  119. } else {
  120. $options['file'] = str_replace('\\', '/', $options['file']);
  121. $rawLink = $traceLine instanceof \Closure ? call_user_func($traceLine, $options, $this) : $traceLine;
  122. return strtr($rawLink, ['{file}' => $options['file'], '{line}' => $options['line'], '{text}' => $options['text']]);
  123. }
  124. }
  125. }