Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
izica committed Jun 10, 2018
1 parent 149521a commit 4800cba
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
20 changes: 17 additions & 3 deletions PhpBrowserLog.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

class PhpBrowserLog
{
public static function script($data, $command = 'console.log', $variable = false)
Expand All @@ -12,7 +13,7 @@ public static function script($data, $command = 'console.log', $variable = false
echo '</script>';
}

public static getVarsNames($arCaller)
public static function getVarsNames($arCaller)
{
$sFile = file_get_contents($arCaller['file']);
$arFile = explode("\n", $sFile);
Expand All @@ -21,7 +22,20 @@ public static function script($data, $command = 'console.log', $variable = false
return explode(',', $arArgsNames);
}

public static print()
public static function log()
{
$arBt = debug_backtrace();
$arCaller = array_shift($arBt);
$arArgsNames = self::getVarsNames($arCaller);

self::script('[' . $arCaller['line'] . '] ' . $arCaller['file'], 'console.groupCollapsed');
foreach ($arCaller['args'] as $nKey => $anyArg) {
self::script($anyArg, 'console.log', $arArgsNames[$nKey]);
}
self::script('', 'console.groupEnd');
}

public static function pre()
{
$arBt = debug_backtrace();
$arCaller = array_shift($arBt);
Expand All @@ -33,4 +47,4 @@ public static function script($data, $command = 'console.log', $variable = false
}
self::script('', 'console.groupEnd');
}
}
}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
You need to use this debug in html view.
You will see result in browser console(F12, Inspect mode console);
```php
PhpBrowserLog::print($arg1, $arg2);
PhpBrowserLog::log($arg1, $arg2);
```

or Aliases
```php
PhpBrowserLog::pre($arg1, $arg2);
pre($arg1, $arg2);
```
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"autoload": {
"classmap": [
"PhpBrowserLog.php"
],
"files": [
"pre.php"
]
}
}
14 changes: 14 additions & 0 deletions pre.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?
require_once 'PhpBrowserLog.php';

function pre(){
$arBt = debug_backtrace();
$arCaller = array_shift($arBt);
$arArgsNames = PhpBrowserLog::getVarsNames($arCaller);

PhpBrowserLog::script('[' . $arCaller['line'] . '] ' . $arCaller['file'], 'console.groupCollapsed');
foreach ($arCaller['args'] as $nKey => $anyArg) {
PhpBrowserLog::script($anyArg, 'console.log', $arArgsNames[$nKey]);
}
PhpBrowserLog::script('', 'console.groupEnd');
}

0 comments on commit 4800cba

Please sign in to comment.