Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## ecco - the console.log() for PHP
- ##### An IntelliJ/PHPStorm Live Template
- ---
- - Go to the Preferences => Editor => Live Templates
- - Select PHP and add a new live template
- - Set "ecco" as abbreviation
- - Add to following:
- ```php
- echo "<script>console.$TYPE$('$FILE$ ($LINE$)', ' ==> $TITLE$: ', ".json_encode([$PARAMS$]).");</script>";
- $END$
- ```
- - Click on "Edit Variables" and add the following into the expressions column:
- | Name | Expression | Default value |Skip if defined
- | ------ | ------ | ------ | ------ |
- | TYPE | | "log" |
- | FILE | __fileName()__ | | ✓
- | LINE | __lineNumber()__ | | ✓
- | TITLE | | |
- | PARAMS | | |
- - Click on define and set to PHP
- - Apply and have fun
- It can also be used as an HTML Live Template surrounded by php tag like this:
- ```php
- <?php echo "<script>console.$TYPE$('$FILE$ ($LINE$)', ' ==> $TITLE$: ', ".json_encode([$PARAMS$]).");</script>"; ?>
- $END$
- ```
- You can pass multiple comma separated variables, as it gets encoded as an array.
- The default console output will be log, but as it's set as a variable you can fastly change it to other types (like: table, error, info, warn). For displaying data in console.table() you need to pass only the pure data like this, or create another live template for it, an "eccoT" i.e.:
- ```php
- echo "<script>console.table(" . json_encode($PARAMS$) . ");</script>";
- ```
- It turned out to be an ideal and fast way to debug in frameworks like WordPress with php file output.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement