HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
Yii2DebugPanel.php
Go to the documentation of this file.
1 <?php
2 
16 class Yii2DebugPanel extends CComponent
17 {
25  public $filterData;
29  protected $_logsEnabled = false;
34  protected $_logsCategories = array();
39  protected $_logsLevels = '';
43  private $_owner;
47  private $_id;
51  private $_tag;
55  private $_data;
59  private $_logRoute;
60 
64  public function getName()
65  {
66  return '';
67  }
68 
72  public function getSummary()
73  {
74  return '';
75  }
76 
80  public function getDetail()
81  {
82  return '';
83  }
84 
89  public function save()
90  {
91  }
92 
97  public function __construct($owner, $id)
98  {
99  $this->_owner = $owner;
100  $this->_id = $id;
101  $this->_tag = $owner->getTag();
102  $this->init();
103  }
104 
108  public function init()
109  {
110  if ($this->_logsEnabled) {
111  $this->initLogRoute();
112  }
113  }
114 
118  public function getOwner()
119  {
120  return $this->_owner;
121  }
122 
127  public function getComponent()
128  {
129  return $this->_owner;
130  }
131 
135  public function getId()
136  {
137  return $this->_id;
138  }
139 
143  public function getTag()
144  {
145  return $this->_tag;
146  }
147 
151  protected function getData()
152  {
153  return $this->_data;
154  }
155 
159  public function getUrl()
160  {
161  return Yii::app()->createUrl($this->getOwner()->moduleId . '/default/view', array(
162  'tag' => $this->getTag(),
163  'panel' => $this->getId(),
164  ));
165  }
166 
171  public function load($data, $tag = null)
172  {
173  if ($tag) $this->_tag = $tag;
174  $this->_data = $data;
175  }
176 
183  public function render($_viewFile_, $_data_ = null)
184  {
185  if (is_array($_data_)) {
186  extract($_data_);
187  } else {
188  $data = $_data_;
189  }
190  ob_start();
191  ob_implicit_flush(false);
192  require($_viewFile_);
193  return ob_get_clean();
194  }
195 
203  public function renderDetail($caption, $values)
204  {
205  return $this->render(dirname(__FILE__) . '/views/panels/_detail.php', array(
206  'caption' => $caption,
207  'values' => $values,
208  ));
209  }
210 
217  public function renderTabs($items)
218  {
219  static $counter = 0;
220  return $this->render(dirname(__FILE__) . '/views/panels/_tabs.php', array(
221  'id' => 'tabs' . ($counter++),
222  'items' => $items,
223  ));
224  }
225 
229  private $_hl;
230 
236  protected function highlightPhp($code)
237  {
238  if ($this->_hl === null) {
239  $this->_hl = Yii::createComponent(array(
240  'class' => 'CTextHighlighter',
241  'language' => 'php',
242  'showLineNumbers' => false,
243  ));
244  }
245  $html = $this->_hl->highlight($code);
246  return strip_tags($html, '<div>,<span>');
247  }
248 
254  protected function getLogs()
255  {
256  if (!$this->_logRoute) {
257  throw new Exception('Yii2DebugLogRoute not initialized.');
258  }
259 
260  return $this->_logRoute->getLogs();
261  }
262 
267  private function initLogRoute()
268  {
269  $config = array(
270  'class' => 'yii2-debug.Yii2DebugLogRoute',
271  'categories' => $this->_logsCategories,
272  'levels' => $this->_logsLevels,
273  );
274 
275  $this->_logRoute = Yii::createComponent($config);
276  $this->_logRoute->init();
277 
278  $routeName = 'yii2debug-' . uniqid();
279  Yii::app()->log->setRoutes(array($routeName => $this->_logRoute));
280  $allRoutes = Yii::app()->log->getRoutes();
281  $this->_logRoute = $allRoutes[$routeName];
282  }
283 }