nyratas/php-console-log 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nyratas/php-console-log

Composer 安装命令:

composer require nyratas/php-console-log

包简介

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

README 文档

README

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

Installation

With Composer

composer require nyratas/php-console-log

Manually

Just download/clone this repository and require the autoload file:

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

Usage

More detailed working examples can be found in the ./examples/ directory.

Don't forget to use the library's facade:

use PHPConsoleLog\Service as Console;

Basic PHP console.log()

Define a place where the library should output the console logs:

Console::exec();

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

$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.

Edit the <script> tag

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

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.

The library generates the following default HTML markup:

<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:

/*
 * 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 !

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.

Enjoy!

统计信息

  • 总下载量: 414
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固