-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ec584ff
Showing
13 changed files
with
804 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/Tests export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
phpunit.xml | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Dump Plus | ||
|
||
With DumpPlus, you can view the content of any variable or object in many different formats: | ||
|
||
* syntax highlighting | ||
* Browsers console log output | ||
* Via Javascript alert() function | ||
* Default var_dump() output | ||
* Command-line interface output | ||
* Simple format | ||
* JSON format | ||
|
||
## Installation | ||
Use Composer to install the library: | ||
``` | ||
$ composer require arashjafari/dump-plus | ||
``` | ||
|
||
## Screenshots | ||
|
||
Screenshot of DumpPlus::pretty($colors); | ||
![pretty](./examples/pretty.png "Screenshot of DumpPlus::pretty") | ||
|
||
Screenshot of DumpPlus::console($colors); | ||
![console](./examples/console.png "Screenshot of DumpPlus::console") | ||
|
||
Screenshot of DumpPlus::alert($colors); | ||
![alert](./examples/alert.png "Screenshot of DumpPlus::alert") | ||
|
||
|
||
## Example | ||
|
||
```php | ||
|
||
use ArashJafari\DumpPlus\DumpPlus; | ||
|
||
// Sample array to dump | ||
$colors = ['key1' => 'red', 'key2' => 'blue']; | ||
|
||
// Default dump output | ||
DumpPlus::dump($colors); | ||
|
||
// Dump with syntax highlighting | ||
DumpPlus::pretty($colors); | ||
|
||
// Dump in simple format | ||
DumpPlus::simple($colors); | ||
|
||
// Dump for CLI output | ||
DumpPlus::cli($colors); | ||
|
||
// Dump in browser console | ||
DumpPlus::console($colors); | ||
|
||
// Dump in Javascript alert! | ||
DumpPlus::alert($colors); | ||
|
||
// Dump in JSON format | ||
DumpPlus::json($colors); | ||
|
||
``` | ||
|
||
Calling with multiple arguments: | ||
|
||
```php | ||
use ArashJafari\DumpPlus\DumpPlus; | ||
|
||
$msg = "Hello World!"; | ||
$colors = ['key1' => 'red', 'key2' => 'blue']; | ||
|
||
DumpPlus::dump($msg, $colors); | ||
``` | ||
|
||
Calling with functions instead of DumpPlus methods: | ||
|
||
```php | ||
|
||
$colors = ['key1' => 'red', 'key2' => 'blue']; | ||
|
||
dp($colors); // DumpPlus::dump($colors); | ||
dpd($colors); // DumpPlus::dump($colors); die(); | ||
|
||
dp_pretty($colors); // DumpPlus::pretty($colors); | ||
dpd_pretty($colors); // DumpPlus::pretty($colors); die(); | ||
|
||
dp_simple($colors); // DumpPlus::simple($colors); | ||
dpd_simple($colors); // DumpPlus::simple($colors); die(); | ||
|
||
dp_cli($colors); // DumpPlus::cli($colors); | ||
dpd_cli($colors); // DumpPlus::cli($colors); die(); | ||
|
||
dp_console($colors); // DumpPlus::console($colors); | ||
dpd_console($colors); // DumpPlus::console($colors); die(); | ||
|
||
dp_alert($colors); // DumpPlus::alert($colors); | ||
dpd_alert($colors); // DumpPlus::alert($colors); die(); | ||
|
||
dp_json($colors); // DumpPlus::json($colors); | ||
dpd_json($colors); // DumpPlus::json($colors); die(); | ||
``` | ||
|
||
## License | ||
|
||
The DumpPlus is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "arashjafari/dump-plus", | ||
"description": "Provides variety of formats for dumps information about variables or objects", | ||
"keywords": ["dump_plus", "dump-plus", "print_r", "var_dump", "debug", "better", "pretty", "print", "dump", "cli", "console.log", "alert"], | ||
"homepage": "https://github.com/arashjafari/dump-plus", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Arash Jafari", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": ">=5.4.0" | ||
}, | ||
"autoload": { | ||
"files": [ "./src/functions.php" ], | ||
"psr-4":{ | ||
"ArashJafari\\DumpPlus\\": "./src/" | ||
|
||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?php | ||
|
||
namespace ArashJafari\DumpPlus; | ||
|
||
class DumpPlus | ||
{ | ||
/** | ||
* Dumps information about a variable. | ||
* | ||
* @param mixed $value The variable you want to export. | ||
* @param mixed ...$values [optional] | ||
* @return void | ||
*/ | ||
public static function dump(mixed $value, ...$values): void | ||
{ | ||
Output::default( | ||
Helpers::groupTitle($value, debug_backtrace()), | ||
Helpers::varDumpContent($value) | ||
); | ||
|
||
foreach ($values as $val) { | ||
static::dump($val); | ||
} | ||
} | ||
|
||
/** | ||
* Dumps information about a variable in a simple format. | ||
* | ||
* @param mixed $value The variable you want to export. | ||
* @param mixed ...$values [optional] | ||
* @return void | ||
*/ | ||
public static function simple(mixed $value, ...$values): void | ||
{ | ||
Output::default( | ||
Helpers::groupTitle($value, debug_backtrace()), | ||
Helpers::printRContent($value) | ||
); | ||
|
||
foreach ($values as $val) { | ||
static::simple($val); | ||
} | ||
} | ||
|
||
/** | ||
* Dumps information about a variable in a highlighted format. | ||
* | ||
* @param mixed $value The variable you want to export. | ||
* @param mixed ...$values [optional] | ||
* @return void | ||
*/ | ||
public static function pretty(mixed $value, ...$values): void | ||
{ | ||
Output::pretty( | ||
Helpers::groupTitle($value, debug_backtrace()), | ||
Helpers::varDumpContent($value) | ||
); | ||
|
||
foreach ($values as $val) { | ||
static::pretty($val); | ||
} | ||
} | ||
|
||
/** | ||
* Dumps information about a variable in CLI. | ||
* | ||
* @param mixed $value The variable you want to export. | ||
* @param mixed ...$values [optional] | ||
* @return void | ||
*/ | ||
public static function cli(mixed $value, ...$values): void | ||
{ | ||
Output::cli( | ||
Helpers::groupTitle($value, debug_backtrace()), | ||
Helpers::varDumpContent($value) | ||
); | ||
|
||
foreach ($values as $val) { | ||
static::cli($val); | ||
} | ||
} | ||
|
||
/** | ||
* Dumps information about a variable in a javascript alert. | ||
* | ||
* @param mixed $value The variable you want to export. | ||
* @param mixed ...$values [optional] | ||
* @return void | ||
*/ | ||
public static function alert(mixed $value, ...$values): void | ||
{ | ||
Output::alert( | ||
Helpers::groupTitle($value, debug_backtrace(), true), | ||
Helpers::printRContent($value) | ||
); | ||
|
||
foreach ($values as $val) { | ||
static::alert($val); | ||
} | ||
} | ||
|
||
/** | ||
* Dumps information about a variable in JSON format. | ||
* | ||
* @param mixed $value The variable you want to export. | ||
* @param mixed ...$values [optional] | ||
* @return void | ||
*/ | ||
public static function json(mixed $value, ...$values): void | ||
{ | ||
header("Content-Type: application/json; charset=UTF-8"); | ||
|
||
Output::json( | ||
Helpers::groupTitle($value, debug_backtrace()), | ||
Helpers::printRContent($value) | ||
); | ||
|
||
foreach ($values as $val) { | ||
static::json($val); | ||
} | ||
} | ||
|
||
/** | ||
* Dumps information about a variable in browser console. | ||
* | ||
* @param mixed $value The variable you want to export. | ||
* @param mixed ...$values [optional] | ||
* @return void | ||
*/ | ||
public static function console(mixed $value, ...$values): void | ||
{ | ||
Output::console( | ||
Helpers::groupTitle($value, debug_backtrace(), true), | ||
Helpers::printRContent($value) | ||
); | ||
|
||
foreach ($values as $val) { | ||
static::console($val); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace ArashJafari\DumpPlus; | ||
|
||
class FileInfo | ||
{ | ||
/** | ||
* Get file path and line number of the caller. | ||
* | ||
* @param array $backtrace | ||
* @return string | ||
*/ | ||
public static function getFileAndLine(array $backtrace, bool $shortTitle): string | ||
{ | ||
$return = ''; | ||
|
||
if (isset($backtrace[0]['file'])) { | ||
$return .= $shortTitle | ||
? basename($backtrace[0]['file']) | ||
: $backtrace[0]['file']; | ||
} | ||
|
||
if (isset($backtrace[0]['line'])) { | ||
$return .= ':' . $backtrace[0]['line']; | ||
} | ||
|
||
return $return; | ||
} | ||
} |
Oops, something went wrong.