Permalink
Browse files

Reformat code te be PSR-2 compatible

  • Loading branch information...
1 parent 77c09e5 commit 7a00d060c15e89b9541fa9f19209c99c5ef40887 @SonicGD SonicGD committed Mar 16, 2014
Showing with 2,046 additions and 2,024 deletions.
  1. +9 −9 DebugAsset.php
  2. +150 −149 LogTarget.php
  3. +136 −135 Module.php
  4. +63 −63 Panel.php
  5. +53 −53 components/search/Filter.php
  6. +18 −18 components/search/matchers/Base.php
  7. +7 −7 components/search/matchers/GreaterThan.php
  8. +7 −7 components/search/matchers/LowerThan.php
  9. +20 −20 components/search/matchers/MatcherInterface.php
  10. +15 −15 components/search/matchers/SameAs.php
  11. +134 −129 controllers/DefaultController.php
  12. +20 −20 models/search/Base.php
  13. +55 −55 models/search/Db.php
  14. +118 −118 models/search/Debug.php
  15. +58 −58 models/search/Log.php
  16. +108 −108 models/search/Mail.php
  17. +55 −55 models/search/Profile.php
  18. +73 −72 panels/ConfigPanel.php
  19. +157 −153 panels/DbPanel.php
  20. +65 −63 panels/LogPanel.php
  21. +83 −82 panels/MailPanel.php
  22. +74 −72 panels/ProfilingPanel.php
  23. +86 −85 panels/RequestPanel.php
  24. +88 −88 views/default/index.php
  25. +18 −18 views/default/panels/config/detail.php
  26. +6 −6 views/default/panels/config/summary.php
  27. +17 −17 views/default/panels/config/table.php
  28. +59 −57 views/default/panels/db/detail.php
  29. +3 −3 views/default/panels/db/summary.php
  30. +60 −59 views/default/panels/log/detail.php
  31. +8 −8 views/default/panels/log/summary.php
  32. +29 −29 views/default/panels/mail/_item.php
  33. +28 −28 views/default/panels/mail/detail.php
  34. +1 −1 views/default/panels/mail/summary.php
  35. +44 −43 views/default/panels/profile/detail.php
  36. +2 −2 views/default/panels/profile/summary.php
  37. +27 −27 views/default/panels/request/detail.php
  38. +6 −6 views/default/panels/request/summary.php
  39. +17 −17 views/default/panels/request/table.php
  40. +10 −10 views/default/toolbar.php
  41. +55 −55 views/default/view.php
  42. +4 −4 views/layouts/main.php
View
@@ -17,13 +17,13 @@
*/
class DebugAsset extends AssetBundle
{
- public $sourcePath = '@yii/debug/assets';
- public $css = [
- 'main.css',
- 'toolbar.css',
- ];
- public $depends = [
- 'yii\web\YiiAsset',
- 'yii\bootstrap\BootstrapAsset',
- ];
+ public $sourcePath = '@yii/debug/assets';
+ public $css = [
+ 'main.css',
+ 'toolbar.css',
+ ];
+ public $depends = [
+ 'yii\web\YiiAsset',
+ 'yii\bootstrap\BootstrapAsset',
+ ];
}
View
@@ -19,153 +19,154 @@
*/
class LogTarget extends Target
{
- /**
- * @var Module
- */
- public $module;
- public $tag;
-
- /**
- * @param \yii\debug\Module $module
- * @param array $config
- */
- public function __construct($module, $config = [])
- {
- parent::__construct($config);
- $this->module = $module;
- $this->tag = uniqid();
- }
-
- /**
- * Exports log messages to a specific destination.
- * Child classes must implement this method.
- */
- public function export()
- {
- $path = $this->module->dataPath;
- if (!is_dir($path)) {
- mkdir($path);
- }
-
- $summary = $this->collectSummary();
- $dataFile = "$path/{$this->tag}.data";
- $data = [];
- foreach ($this->module->panels as $id => $panel) {
- $data[$id] = $panel->save();
- }
- $data['summary'] = $summary;
- file_put_contents($dataFile, serialize($data));
-
- $indexFile = "$path/index.data";
- $this->updateIndexFile($indexFile, $summary);
- }
-
- /**
- * Updates index file with summary log data
- *
- * @param string $indexFile path to index file
- * @param array $summary summary log data
- * @throws \yii\base\InvalidConfigException
- */
- private function updateIndexFile($indexFile, $summary)
- {
- touch($indexFile);
- if (($fp = @fopen($indexFile, 'r+')) === false) {
- throw new InvalidConfigException("Unable to open debug data index file: $indexFile");
- }
- @flock($fp, LOCK_EX);
- $manifest = '';
- while (($buffer = fgets($fp)) !== false) {
- $manifest .= $buffer;
- }
- if (!feof($fp) || empty($manifest)) {
- // error while reading index data, ignore and create new
- $manifest = [];
- } else {
- $manifest = unserialize($manifest);
- }
-
- $manifest[$this->tag] = $summary;
- $this->gc($manifest);
-
- ftruncate($fp, 0);
- rewind($fp);
- fwrite($fp, serialize($manifest));
-
- @flock($fp, LOCK_UN);
- @fclose($fp);
- }
-
- /**
- * Processes the given log messages.
- * This method will filter the given messages with [[levels]] and [[categories]].
- * And if requested, it will also export the filtering result to specific medium (e.g. email).
- * @param array $messages log messages to be processed. See [[Logger::messages]] for the structure
- * of each message.
- * @param boolean $final whether this method is called at the end of the current application
- */
- public function collect($messages, $final)
- {
- $this->messages = array_merge($this->messages, $messages);
- if ($final) {
- $this->export($this->messages);
- }
- }
-
- protected function gc(&$manifest)
- {
- if (count($manifest) > $this->module->historySize + 10) {
- $n = count($manifest) - $this->module->historySize;
- foreach (array_keys($manifest) as $tag) {
- $file = $this->module->dataPath . "/$tag.data";
- @unlink($file);
- unset($manifest[$tag]);
- if (--$n <= 0) {
- break;
- }
- }
- }
- }
-
- /**
- * Collects summary data of current request.
- * @return array
- */
- protected function collectSummary()
- {
- $request = Yii::$app->getRequest();
- $response = Yii::$app->getResponse();
- $summary = [
- 'tag' => $this->tag,
- 'url' => $request->getAbsoluteUrl(),
- 'ajax' => $request->getIsAjax(),
- 'method' => $request->getMethod(),
- 'ip' => $request->getUserIP(),
- 'time' => time(),
- 'statusCode' => $response->statusCode,
- 'sqlCount' => $this->getSqlTotalCount(),
- ];
-
- if (isset($this->module->panels['mail'])) {
- $summary['mailCount'] = count($this->module->panels['mail']->getMessages());
- }
-
- return $summary;
- }
-
- /**
- * Returns total sql count executed in current request. If database panel is not configured
- * returns 0.
- * @return integer
- */
- protected function getSqlTotalCount()
- {
- if (!isset($this->module->panels['db'])) {
- return 0;
- }
- $profileLogs = $this->module->panels['db']->getProfileLogs();
-
- # / 2 because messages are in couple (begin/end)
- return count($profileLogs) / 2;
- }
+ /**
+ * @var Module
+ */
+ public $module;
+ public $tag;
+
+ /**
+ * @param \yii\debug\Module $module
+ * @param array $config
+ */
+ public function __construct($module, $config = [])
+ {
+ parent::__construct($config);
+ $this->module = $module;
+ $this->tag = uniqid();
+ }
+
+ /**
+ * Exports log messages to a specific destination.
+ * Child classes must implement this method.
+ */
+ public function export()
+ {
+ $path = $this->module->dataPath;
+ if (!is_dir($path)) {
+ mkdir($path);
+ }
+
+ $summary = $this->collectSummary();
+ $dataFile = "$path/{$this->tag}.data";
+ $data = [];
+ foreach ($this->module->panels as $id => $panel) {
+ $data[$id] = $panel->save();
+ }
+ $data['summary'] = $summary;
+ file_put_contents($dataFile, serialize($data));
+
+ $indexFile = "$path/index.data";
+ $this->updateIndexFile($indexFile, $summary);
+ }
+
+ /**
+ * Updates index file with summary log data
+ *
+ * @param string $indexFile path to index file
+ * @param array $summary summary log data
+ * @throws \yii\base\InvalidConfigException
+ */
+ private function updateIndexFile($indexFile, $summary)
+ {
+ touch($indexFile);
+ if (($fp = @fopen($indexFile, 'r+')) === false) {
+ throw new InvalidConfigException("Unable to open debug data index file: $indexFile");
+ }
+ @flock($fp, LOCK_EX);
+ $manifest = '';
+ while (($buffer = fgets($fp)) !== false) {
+ $manifest .= $buffer;
+ }
+ if (!feof($fp) || empty($manifest)) {
+ // error while reading index data, ignore and create new
+ $manifest = [];
+ } else {
+ $manifest = unserialize($manifest);
+ }
+
+ $manifest[$this->tag] = $summary;
+ $this->gc($manifest);
+
+ ftruncate($fp, 0);
+ rewind($fp);
+ fwrite($fp, serialize($manifest));
+
+ @flock($fp, LOCK_UN);
+ @fclose($fp);
+ }
+
+ /**
+ * Processes the given log messages.
+ * This method will filter the given messages with [[levels]] and [[categories]].
+ * And if requested, it will also export the filtering result to specific medium (e.g. email).
+ * @param array $messages log messages to be processed. See [[Logger::messages]] for the structure
+ * of each message.
+ * @param boolean $final whether this method is called at the end of the current application
+ */
+ public function collect($messages, $final)
+ {
+ $this->messages = array_merge($this->messages, $messages);
+ if ($final) {
+ $this->export($this->messages);
+ }
+ }
+
+ protected function gc(&$manifest)
+ {
+ if (count($manifest) > $this->module->historySize + 10) {
+ $n = count($manifest) - $this->module->historySize;
+ foreach (array_keys($manifest) as $tag) {
+ $file = $this->module->dataPath . "/$tag.data";
+ @unlink($file);
+ unset($manifest[$tag]);
+ if (--$n <= 0) {
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Collects summary data of current request.
+ * @return array
+ */
+ protected function collectSummary()
+ {
+ $request = Yii::$app->getRequest();
+ $response = Yii::$app->getResponse();
+ $summary = [
+ 'tag' => $this->tag,
+ 'url' => $request->getAbsoluteUrl(),
+ 'ajax' => $request->getIsAjax(),
+ 'method' => $request->getMethod(),
+ 'ip' => $request->getUserIP(),
+ 'time' => time(),
+ 'statusCode' => $response->statusCode,
+ 'sqlCount' => $this->getSqlTotalCount(),
+ ];
+
+ if (isset($this->module->panels['mail'])) {
+ $summary['mailCount'] = count($this->module->panels['mail']->getMessages());
+ }
+
+ return $summary;
+ }
+
+ /**
+ * Returns total sql count executed in current request. If database panel is not configured
+ * returns 0.
+ * @return integer
+ */
+ protected function getSqlTotalCount()
+ {
+ if (!isset($this->module->panels['db'])) {
+ return 0;
+ }
+ $profileLogs = $this->module->panels['db']->getProfileLogs();
+
+ # / 2 because messages are in couple (begin/end)
+
+ return count($profileLogs) / 2;
+ }
}
Oops, something went wrong.

0 comments on commit 7a00d06

Please sign in to comment.