Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. ## ecco - the console.log() for PHP
  2. ##### An IntelliJ/PHPStorm Live Template
  3. ---
  4. - Go to the Preferences => Editor => Live Templates
  5. - Select PHP and add a new live template
  6. - Set "ecco" as abbreviation
  7. - Add to following:
  8. ```php
  9. echo "<script>console.$TYPE$('$FILE$ ($LINE$)', ' ==> $TITLE$: ', ".json_encode([$PARAMS$]).");</script>";
  10. $END$
  11. ```
  12. - Click on "Edit Variables" and add the following into the expressions column:
  13.  
  14. | Name | Expression | Default value |Skip if defined
  15. | ------ | ------ | ------ | ------ |
  16. | TYPE | | "log" |
  17. | FILE | __fileName()__ | | ✓
  18. | LINE | __lineNumber()__ | | ✓
  19. | TITLE | | |
  20. | PARAMS | | |
  21.  
  22. - Click on define and set to PHP
  23. - Apply and have fun
  24.  
  25. It can also be used as an HTML Live Template surrounded by php tag like this:
  26. ```php
  27. <?php echo "<script>console.$TYPE$('$FILE$ ($LINE$)', ' ==> $TITLE$: ', ".json_encode([$PARAMS$]).");</script>"; ?>
  28. $END$
  29. ```
  30.  
  31. You can pass multiple comma separated variables, as it gets encoded as an array.
  32.  
  33. 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.:
  34. ```php
  35. echo "<script>console.table(" . json_encode($PARAMS$) . ");</script>";
  36. ```
  37.  
  38. 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