2017 © Pedro Peláez
 

library php-console-log

image

nyratas/php-console-log

  • Monday, April 2, 2018
  • by Nyratas
  • Repository
  • 2 Watchers
  • 6 Stars
  • 341 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 15 % Grown

The README.md

PHP console.log()

PHP console.log() allows you to dump PHP variables in the browser's console. It is an easy-to-use and lightweight PHP library., (*1)

Installation

With Composer

composer require nyratas/php-console-log

Manually

Just download/clone this repository and require the autoload file:, (*2)

require_once(__DIR__ . '/PHPConsoleLog/__autoload.php');

Usage

More detailed working examples can be found in the ./examples/ directory., (*3)

Don't forget to use the library's facade:, (*4)

use PHPConsoleLog\Service as Console;

Basic PHP console.log()

Define a place where the library should output the console logs:, (*5)

Console::exec();

You can now use the Console::log() method everywhere, as long as it is called before a Console::exec() call., (*6)

$myArray = ['one','two','three'];

Console::log($myArray);

You can use Console::log() with any type of variable. If you want to output an PHP array or object, the library will show a JavaScript Array or Object in the browser's console. A boolean will remain a boolean, an integer will remain an integer, a string remain a string, and so on., (*7)

Edit the <script> tag

All this library does is generating a <script>-tag at the location of the Console::exec() call., (*8)

This tag contains the required JavaScript logic in order to output the requested data in the browser's console. There is not much you can do on the generated JavaScript code, but you could want to add an attribute on the <script> tag., (*9)

The library generates the following default HTML markup:, (*10)

<script type="text/javascript" data-php-console-log="true">
      [...]
</script>

You can remove or modify the data-php-console-log attribute by setting it as follows:, (*11)

/*
 * Remove the attribute :
 */

Console::setAttribute();
      // or
Console::setAttribute(false);


/*
 * Edit the attribute :
 */

      // simple attribute
Console::setAttribute('data-my-attribute');
      // attribute with value
Console::setAttribute('data-my-attribute','attribute-value');

Wordpress tip

Do you want to use this library on a wordpress theme ? Just add the following line in your functions.php file and start Console::log()-ing right now !, (*12)

add_action( 'wp_footer', function(){ Console::exec(); }, 100 );

What now ?

Well, I wrote this library in a hurry, so there's probably a lot to change/add. Feel free to contribute or to request some changes., (*13)

Enjoy!, (*14)

The Versions

02/04 2018

v1.0

1.0.0.0

  Sources   Download

06/03 2018

v1.1

1.1.0.0

  Sources   Download

26/05 2016

dev-master

9999999-dev https://github.com/Nyratas/php-console-log

Displays var_dump()s in the browser's JavaScript console.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

debug log php logging console javascript error var_dump console.log

26/05 2016

v1.1.0

1.1.0.0 https://github.com/Nyratas/php-console-log

Displays var_dump()s in the browser's JavaScript console.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

debug log php logging console javascript error var_dump console.log