Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
izica committed Jun 10, 2018
1 parent 6de3139 commit 149521a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 izica

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
36 changes: 36 additions & 0 deletions PhpBrowserLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
class PhpBrowserLog
{
public static function script($data, $command = 'console.log', $variable = false)
{
echo '<script>';
if ($variable === false) {
echo $command . '(' . json_encode($data) . ')';
} else {
echo $command . '("' . trim($variable) . '",' . json_encode($data) . ')';
}
echo '</script>';
}

public static getVarsNames($arCaller)
{
$sFile = file_get_contents($arCaller['file']);
$arFile = explode("\n", $sFile);
$arArgsNames = explode('(', $arFile[$arCaller[line] - 1])[1];
$arArgsNames = explode(')', $arArgsNames)[0];
return explode(',', $arArgsNames);
}

public static print()
{
$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');
}
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# php-browser-log
## Usage
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);
```
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "izica/php-browser-log",
"description": "Pretty log in browser console",
"authors": [
{
"name": "Golovarchuk Artyom",
"email": "artemiztomska@gmail.com"
}
],
"keywords": ["log", "php", "logger", "browser"],
"license": "MIT",
"require": {
"php": ">=5.6.0"
},
"autoload": {
"classmap": [
"PhpBrowserLog.php"
]
}
}

0 comments on commit 149521a

Please sign in to comment.